+ 1

user_input == input(':') 1=add 2=subtract 3=multiply 4=divide 5=quit if user_input ==(5) break elif user_input ==(1) num1 = fl

why this get a syntax error

8th Nov 2016, 8:36 PM
leonardo
leonardo - avatar
4 Respuestas
+ 1
First line, you don't need == since you don't test if it's equal but you assign it. Next, I don't believe you can use numbers as variable names. Finally, you need to add ':' at the end of the lines of your if and elif, and to indent the lines concerned by the condition.
8th Nov 2016, 8:51 PM
Pierre Varlez
Pierre Varlez - avatar
+ 1
I believe you try to do some kind of basic calculator? Your code is surely inside a while loop, it should look like something like that : print("1=add") print("2=substract") print("3=multiply") print("4=divide") print("other=quit") while True: user_input = input("What do you want? ") if(user_input == 1): # Do the addition code elif(user_input == 2): # Do the substraction code # Do the other cases else: break
8th Nov 2016, 9:22 PM
Pierre Varlez
Pierre Varlez - avatar
0
i've changed the variable but I still get a syntax error and it says that somehow user_input is wrong
8th Nov 2016, 8:57 PM
leonardo
leonardo - avatar
0
thanks I was trying to short rhe basic calculator of the second part of the python course, sorry for wasting your time
8th Nov 2016, 9:26 PM
leonardo
leonardo - avatar