+ 1
simple calculator in py having problem plz help
3 odpowiedzi
+ 1
I found nothing wrong with it. Add indentations if you didn't. I would highly recommend using a more complicated online compiler like https://trinket.io/ . This is the code that I ran, I needed to add indentations but thats it. I ran your code in my computers IDLE, and in trinket.io, it worked perfectly fine, must be something with Solo Learn. I believe the errors was in the indentation in the while loop: After the while loop everthing needs to be indented.
while True:
print("options")
print ("enter 'add'to add two numbers")
print ("enter'subtract'to subtract two numbers")
print("enter'multiply'to multiply two numbers")
print ("enter'divide'to divide 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 another number"))
result=str(num1*num2)
print ("the answer is"+result)
elif user_input=="divide":
num1=float(input("enter a number"))
num2=float(input("enter another number"))
result=str(num1/num2)
print ("the answer is"+result)
else:
print("bye")
0
this is the code plz help
while True:
print("options")
print ("enter 'add'to add two numbers")
print ("enter'subtract'to subtract two numbers")
print("enter'multiply'to multiply two numbers")
print ("enter'divide'to divide 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 another number"))
result=str(num1*num2)
print ("the answer is"+result)
elif user_input=="divide":
num1=float(input("enter a number"))
num2=float(input("enter another number"))
result=str(num1/num2)
print ("the answer is"+result)
else:
print("bye")
0
all i see is the indentation for user_input=input(":") that needs to be indented and if user_input=="quit": needs to be too same with the break needs one more indent