0
when using the elif for 2nd time its showing error
if user=="quit": break elif user =='add': print (______) elif user=='sub': the 2nd elif is showing error pls help
4 Answers
+ 1
Do you have a block after it, or is that all the code? Also, you should indent the break. And if you could provide more info about the error, it would be more helpful.
+ 1
help please
+ 1
indentation is everything in python. every time you un-indent something (like the print function on the line above your 2nd elif) python interpets that as exiting the block of code. in this situation, that means it does not expect any more code from your if statement, and since you cannot begin with elif it throws an error.
indent your code properly and it should work fine.
0
complete prog
while True:
print("option")
print("enter 'add' to add two numbers")
print(" enter 'sub' to substract two numbers")
print("enter 'multiply' to multiply two numbers:")
print("enter 'multiply' to multiply two numbers:")
print("enter 'division' tp divide two numbers:")
print("enter 'quit' to end the program")
user=input(":")
if user=="quit":
break
elif user =='add':
num1=float(input("enter a number: "))
num2=float(input("enter another number: "))
result=str(num1+num2)
print("the answer is: "+result)
elif user == 'sub':
num1=float(input("enter a number: "))
num2=float(input("enter another number: "))
result=str(num1-num2)
print("the answer is: "+result)
elif user=="multiply":
num1=float(input("enter a number: "))
num2=float(Input("enter another number: "))
result=str(num1*num2)
print("the answer is: "+result)
elif user=="division":
num1=float(input("enter a number: "))
num2=float(input("enter another number: "))
result=str(num1/num2)
print("the answer is: "+result)
else
Print('unknown Input')