New course! Every coder should learn Generative AI!
Try a free lesson0
Why won't this compile correctly? Python
I am trying to make a game in python. However, when I compile this it says that game isn't defined. can anyone help? if user_resp == str("start"): game() else: print ("b") def game(): print("you wake up in a room with two doors") print("which door will you choose?") print ("left or right") user_resp == raw_input if user_resp == str("left"): print ("you chose the left door") elif user_resp == str("right"): print ("you chose the right door") else: print ("that wasnt an option....")
2 Answers
+ 6
You have to define the method *before* you call it.
0
Like Kuba said:
def game():
print("you wake up in a room with two doors")
print("which door will you choose?")
print ("left or right")
user_resp == raw_input
if user_resp == str("left"):
print ("you chose the left door")
elif user_resp == str("right"):
print ("you chose the right door")
else:
print ("that wasnt an option....").
if user_resp == str("start"):
game()
else:
print ("b")