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
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
+ 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 .
+ 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
0
indent in where of the cod ?
0
no there is indent on those lines but still show errors one see my cod
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)