MLCLOUD
MLCLOUD

Reputation: 11

How to print function on if statement?

How do I print the function 'play' in the if statement on line 5?

print("Deal 'Em\nby Imago Games")
print("1. Play\n2. Credits")
select = input()
if select == 1:
    def play()
elif select == 1:
    print("Bye")
def play():
    print("Welcome to Deal 'Em\nLet me teach you the basics!")

Upvotes: 0

Views: 274

Answers (4)

Klaus D.
Klaus D.

Reputation: 14369

There are three major problems in your code:

  • play() is defined before usage. You have to define the function earlier in your code.
  • to call the function use play() without def
  • your elif has the same condition as the if and will never be executed

Upvotes: 3

Nirvik Baruah
Nirvik Baruah

Reputation: 1793

Instead of def play() on line 5, use play() to simply call the function. Also, you should work on the structure of your code and place all the function definitions before calling them.

Upvotes: 0

Lucas Leite
Lucas Leite

Reputation: 58

Just leave it as play(), the print is already inside the function

Upvotes: 0

bananafish
bananafish

Reputation: 2917

You can put either just play() on line 5 (remove the def) or change the play function to return the string instead of printing it. def is only used when you define the function, not when you call it.

Upvotes: 0

Related Questions