Can inputs be used as a variable? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Can inputs be used as a variable?

I am trying to create a quiz in Python that uses user input and of course booleans. At the moment here is my code. score = 0 print("Welcome to the quiz") print("What is the Capital of Iceland") print(" A Reykjavik") print("B. Villinus") input("Please write your answer") if input = A print ("Correct") score = 1 else ("Sorry that is incorrect the answer is A") Unfortunately The error is: File "file0.py", line 7 if input = A ^ SyntaxError: invalid syntax Can someone tell me how to phrase my code in the right way and tell me what I am doing wrong

1st Sep 2021, 5:40 PM
Hack
Hack - avatar
3 Respuestas
+ 4
first assign that input function to a variable: user_input = input("Please write your answer") then, correct the mistake at conditional statement. change if input = A to if user_input == "A" Explanation: input() will return what the user put in the terminal input = A is an assignment operator where you assign A to some variable input the A in that expression is not a string user_input== "A" is what you want to do. that is where you compare user_input with "A". The reason why you must right "A" (with quotation is) by default, the return value you get from input() function is a string. So, that string is stored in variable user_input. You want to compare that user_input with another string if that make sense
1st Sep 2021, 5:50 PM
Shahrull Fytri
Shahrull Fytri - avatar
+ 2
See this and see it in detail, my code is the right code, if any problems in understanding then message me Okey Happy Coding! https://code.sololearn.com/c9O1lr45HJv3/?ref=app
1st Sep 2021, 5:49 PM
<★Shaurya Chauhan★>(ACTIVE AGAIN✌😇🙃)
<★Shaurya Chauhan★>(ACTIVE AGAIN✌😇🙃) - avatar
+ 1
Thank you very much
1st Sep 2021, 5:56 PM
Hack
Hack - avatar