0

What is the problem in this code ?

elif user_input == "sub": the problem shows in line 16 of my calculator in elif shows syntax error

26th Apr 2018, 8:13 AM
Jamaluddin Huseinkhail
Jamaluddin Huseinkhail - avatar
6 Answers
+ 2
while True: #not "true" python is case sensitive! print ("options:") print ("enter 'add' to add two numbers") print ("enter 'sub' to subtract two numbers") print ("enter 'multiply' to multiply two numbers") print ("enter 'devide' to devide two numbers") print ("enter 'qiute' to end the program") user_input = input(":") if user_input == "qiute": #double quotation! #There must be indentation in a statement. break elif user_input == "add": num1 = float (input("enter a number:")) num2 = float (input("enter another number:")) result = str(num1 + num2) print ("the answer is" + result) elif user_input == "sub": num1 = float (input("enter a number:")) num2 = float (input("enter another number :")) result = str (num1 - num2) print ("the answer is" + result) elif user_input == "multiply": num1 = float (input("enter a number:")) num2 = float (input("enter another number :")) result = str (num1 * num2) print ("the answer is" + result) elif user_input == "devide": num1 = float (input("enter a number:")) num2 = float (input("enter another number:")) result = str (num1 / num2) print ("the answer is" + result) #don't use "/" operator to concatenate the strings. else : break
26th Apr 2018, 1:06 PM
Disvolviĝo;
Disvolviĝo; - avatar
+ 1
I suspect the cause is that there is no indent in the previous line. In the other elif statements, there is no indent , either .
26th Apr 2018, 8:22 AM
Disvolviĝo;
Disvolviĝo; - avatar
+ 1
elif user_input == "add": num1 = float (input("enter a number:")) num2 = float (input("enter another number:")) result = str(num1 + num2) // here print ("the answer is" + result) //here
26th Apr 2018, 10:02 AM
Disvolviĝo;
Disvolviĝo; - avatar
0
indent in where of the cod ?
26th Apr 2018, 8:55 AM
Jamaluddin Huseinkhail
Jamaluddin Huseinkhail - avatar
0
no there is indent on those lines but still show errors one see my cod
26th Apr 2018, 12:41 PM
Jamaluddin Huseinkhail
Jamaluddin Huseinkhail - avatar
0
elif user_input == "multiply": num1 = float(input("Enter a number: ")) num2 = float (input("enter another number:")) result = str(num1 * num2) print ("the answer is" + result)
23rd Aug 2019, 3:14 PM
Connor Turner