+ 2
Please I am having problems with this calculator code, help me while stating the solutions in withing the code. Thanks a lot
2 odpowiedzi
+ 6
# some improper indentations, wrong keywords, etc.
# please compare with original code.
# remember to split input into multiple lines, e.g.
# add
# 1
# 2
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 the program")
user_input = input(": ")
if user_input == "quit":
pass
elif user_input == "add":
num1 = float(input("gimme a number"))
num2 = float(input("gimme another number"))
result=str(num1 + num2 )
elif user_input == "subtract":
num1=float(input("gimme a number"))
num2=float(input("gimme another number"))
result=str(num1 - num2 )
elif user_input == "multiply":
num1=float(input("gimme a number"))
num2=float(input("gimme another number"))
result=str(num1 * num2 )
elif user_input == "divide":
num1=float(input("gimme a number"))
num2=float(input("gimme another number"))
result=str(num1 / num2 )
else:
result = 'undefined'
print("result is" + result )
+ 2
Thanks for your reply Hasty Rei
code didn't run though
gave me EOFError for line 19 when I tried to add