#๐Ÿ”’ string or dict?

20 messages ยท Page 1 of 1 (latest)

noble escarp
#

heyyy, I wanted to know if, in my function I set the return to be a print of a value in a dict, is the return type a dict or a string ? (the value in the dict is a str)

my code for reference:

HANGMAN_PHOTOS = {
    0: """    x-------x""",
    1: """    x-------x
    |
    |
    |
    |
    |""",
    2: """    x-------x
    |       |
    |       0
    |
    |
    |""",
    3: """    x-------x
    |       |
    |       0
    |       |
    |
    |""",
    4: """    x-------x
    |       |
    |       0
    |      /|\\
    |
    |""",
    5: """    x-------x
    |       |
    |       0
    |      /|\\
    |      /
    |""",
    6: """    x-------x
    |       |
    |       0
    |      /|\\
    |      / \\
    |"""
}
def print_hangman(num_of_tries):
    """The function prints one of the seven states of the hanging man.
    :param num_of_tries: number from 0-6
    :type num_of_tries: int
    :return: str?
    :rtype: str?
    """
    print(HANGMAN_PHOTOS[int(num_of_tries)])

def main():
    # Call the function print_hangman
    num_of_tries = 6
    print_hangman(num_of_tries)
if (__name__ == "__main__"):
    main()
latent larkBOT
#

@noble escarp

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

noble escarp
#

dont worry about the code iteself

#

I just want to know the return type

#

!e ```py
HANGMAN_PHOTOS = {
0: """ x-------x""",
1: """ x-------x
|
|
|
|
|""",
2: """ x-------x
| |
| 0
|
|
|""",
3: """ x-------x
| |
| 0
| |
|
|""",
4: """ x-------x
| |
| 0
| /|\
|
|""",
5: """ x-------x
| |
| 0
| /|\
| /
|""",
6: """ x-------x
| |
| 0
| /|\
| / \
|"""
}
def print_hangman(num_of_tries):
"""The function prints one of the seven states of the hanging man.
:param num_of_tries: number from 0-6
:type num_of_tries: int
:return: str?
:rtype: str?
"""
print(HANGMAN_PHOTOS[int(num_of_tries)])

def main():
# Call the function print_hangman
num_of_tries = 6
print_hangman(num_of_tries)
if (name == "main"):
main()

latent larkBOT
#

@noble escarp :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 |     x-------x
002 |     |       |
003 |     |       0
004 |     |      /|\
005 |     |      / \
006 |     |
bitter scarab
#

set the return to be a print of a value in a dict
this doesnt make sense, printing and returning are two different things

#

printing means displaying some string in the console, returning is how python evaluates the function call expression

#

!return-gif

latent larkBOT
#
Print and return

Here's a handy animation demonstrating how print and return differ in behavior.

See also: /tag return

noble escarp
#

you're right my bad

bitter scarab
#

so since your function does not have an explicit return statement, it returns None by default

noble escarp
#

how about this then :

#
def print_hangman(num_of_tries):
    """The function prints one of the seven states of the hanging man.
    :param num_of_tries: number from 0-6
    :type num_of_tries: int
    :return: one of the seven states of the hanging man
    :rtype: str
    """
    return HANGMAN_PHOTOS[int(num_of_tries)]
bitter scarab
#

the return type would by the type of HANGMAN_PHOTOS[int(num_of_tries)], which is a string

noble escarp
#

alright thanks !

bitter scarab
#

np

noble escarp
#

!close

latent larkBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.