when using the elif for 2nd time its showing error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

26th Sep 2016, 10:15 AM
David Basumatary
David Basumatary - avatar
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.
26th Sep 2016, 10:22 AM
Zen
Zen - avatar
+ 1
help please
26th Sep 2016, 10:33 AM
David Basumatary
David Basumatary - avatar
+ 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.
26th Sep 2016, 5:10 PM
Luke Armstrong
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')
26th Sep 2016, 10:31 AM
David Basumatary
David Basumatary - avatar