Why won't this compile correctly? Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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....")

12th Oct 2017, 4:55 PM
Stef
Stef - avatar
2 Answers
+ 6
You have to define the method *before* you call it.
12th Oct 2017, 5:00 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
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")
12th Oct 2017, 5:03 PM
Niush
Niush - avatar