+ 2

what did i do wrong in this calculator its not working?(python)

https://code.sololearn.com/cITZYRPC8JB9/#py

15th Sep 2018, 11:51 AM
tarok
tarok - avatar
4 Answers
+ 5
The first elif should be an if. And the indentions of all elifs is wrong (one space to much) https://code.sololearn.com/cn89ZTNFPguI/?ref=app
15th Sep 2018, 12:32 PM
Paul
Paul - avatar
+ 1
You have to use if everytime you want to start an if statements etc if user_input == “quit”: break elif user_input == “add”: (your code) alwayd remember to indent with 4 spaces
15th Sep 2018, 4:24 PM
Xodia Gaming
Xodia Gaming - avatar
0
while True: print('Options') print("Enter 'add' to add two number") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'quit' to end program") user_input=input(":") if user_input=='quit': 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=='subtract': 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 a number:')) result=str(num1*num2) print('THE ANSWER IS '+ result) I did some modifications, ie result of option multiply was num1-num2, I changed to num1*num2. I added an space at the end of THE ANSWER IS
15th Sep 2018, 10:15 PM
Lucas Collino
Lucas Collino - avatar
0
I think you didn't see the 'break' statement, Artem Khaiet. It gets the program out of the loop if you input quit.
16th Sep 2018, 6:32 AM
Paul
Paul - avatar