+ 2
what did i do wrong in this calculator its not working?(python)
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
+ 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
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
0
I think you didn't see the 'break' statement, Artem Khaiet. It gets the program out of the loop if you input quit.