0

Python Calculator: Syntax error in line 10

Hi guys, I have just finished programming a calculator in python. However, whenever I run the code I get this error File "./Playground/file0.py", line 10 if user_input=("quit"): ^ SyntaxError: invalid syntax Do you guys have any Idea why this is happening? This is my code... while True: print("type 'add' to add two numbers") print("type 'subtract' to subtract two numbers") print ("type 'divide' to divide two numbbers") print ("type 'multiply' to multiply two numbers ") print ("type 'quit' to terminate the process") user_input=input(":") if user_input=("quit"): break elif user_input=("add"): number_1=float(input("enter a number")) number_2=float(input("enter another number")) result=(number_1+number_2) print("The answer is"+result) elif user_input=("subtract"): number_1=float(input("enter a number")) number_2=float(input("enter another number")) result=(number_1-number_2) print("The Answer is"+result) elif user_input=("multiply"): number_1=float(input("enter a number")) number_1=float(input("enter another number")) result=(number_1+number_2) print("The answer is"+result) elif user_input=(divide): number_1=float(input("enter a number")) number_2=float(input("enter another number")) result=(number_1+number_2) print("The answer is"+result) else: print ("unknown input")

2nd Feb 2020, 7:33 PM
Cillian
Cillian - avatar
7 Respuestas
+ 5
You need add == . See also identation. If user_input == "quit" : break elif user_input == "subtract": # do something
2nd Feb 2020, 7:43 PM
Pedro H.J
Pedro H.J - avatar
+ 3
..okaay, right now I see it's different again. At the very beginning of this question I replied first but after refresh I saw I commented after Pedro and right after Black Jesus. But right now as I'm writing this comment it's again me who answered first :D
2nd Feb 2020, 8:01 PM
r8w9
r8w9 - avatar
2nd Feb 2020, 7:40 PM
r8w9
r8w9 - avatar
+ 2
r8w9 No problem. I think your comment is ok.
2nd Feb 2020, 9:29 PM
Pedro H.J
Pedro H.J - avatar
+ 1
Pedro H.J , Błack Jesus❕ sorry guys, I didn't see your replies so don't think I wanted to fulfill your response ^^
2nd Feb 2020, 7:57 PM
r8w9
r8w9 - avatar
0
Thanks guys
3rd Feb 2020, 6:28 AM
Cillian
Cillian - avatar