+ 1

How do I put a variable under an if statement?

I am making a multiple choice game. I want it to be like this: if the input is A, print a prompt that asks for input. Here it is... What's the issue? Thanks! choice_1 = input("\n Choose a letter. \n A: AAA \n B: BBB \n") if choice_1 == 'A': print("XYZ") choice_2 = input("A: ABC \n B: DEF \n C: GHI \n"): if choice_2 == 'A': print("XYZ") elif choice_2 == 'B': print("UVW") elif choice_2 == 'C': print("RST") else: print("That is not a choice") elif choice_1 == 'B': print("XYZ") choice_3 = input("A: ABC B: DEF \n C: GHI D: JKL"): if choice_3 == 'A': print("XYZ") elif choice_3 == 'B': print("UVW") elif choice_3 == 'C': print("RST") elif choice_3 == 'D': print("OPQ") else: print("That is not a choice") else: print("That is not a choice.")

10th Nov 2017, 3:59 AM
Nitay Eshed
Nitay Eshed - avatar
8 Respostas
+ 2
There shouldn't be a colon after input(); choice_2 = input("A: ABC...\n") if ... etc Try again and tell me if it works (correct the same mistake for choice_3). Don't forget to remove the unnecessary indentations.
10th Nov 2017, 4:10 AM
blackcat1111
blackcat1111 - avatar
+ 2
Are you trying in Code Playground? Remember to separate the inputs by putting a line in between.
10th Nov 2017, 4:20 AM
blackcat1111
blackcat1111 - avatar
+ 2
That's weird; it works perfectly fine for me. Try this: choice_1 = input("\n Choose a letter. \n A: AAA \n B: BBB \n") if choice_1 == 'A': print("XYZ") choice_2 = input("A: ABC \n B: DEF \n C: GHI \n") if choice_2 == 'A': print("XYZ") elif choice_2 == 'B': print("UVW") elif choice_2 == 'C': print("RST") else: print("That is not a choice") elif choice_1 == 'B': print("XYZ") choice_3 = input("A: ABC B: DEF \n C: GHI D: JKL") if choice_3 == 'A': print("XYZ") elif choice_3 == 'B': print("UVW") elif choice_3 == 'C': print("RST") elif choice_3 == 'D': print("OPQ") else: print("That is not a choice") else: print("That is not a choice.")
10th Nov 2017, 4:26 AM
blackcat1111
blackcat1111 - avatar
+ 1
Removed the colon after input() for lines 6 and 18, and unnecessary indentations for the if/elif/else statements.
10th Nov 2017, 4:35 AM
blackcat1111
blackcat1111 - avatar
0
originally, the error is choice_2 not defined
10th Nov 2017, 4:19 AM
Nitay Eshed
Nitay Eshed - avatar
0
I'm in vs studio
10th Nov 2017, 4:20 AM
Nitay Eshed
Nitay Eshed - avatar
0
now it's invalid syntax
10th Nov 2017, 4:24 AM
Nitay Eshed
Nitay Eshed - avatar
0
what did you change
10th Nov 2017, 4:29 AM
Nitay Eshed
Nitay Eshed - avatar