+ 1
What's wrong? I can't found a mistake. (It is copy code)
3 Antworten
+ 2
You're operating on number before taking its inputs..
So first take input then take required arithmetic operation input, perform operation, display result..
For ex for adding:
num1 = float(input("Enter a number: "))
num2 = float(input("Enter another number: "))
#now here you have num1, num2 values, now take input for operation for ex : add, then by this you get addition
user_input = input(": ")
if user_input == "add":
result = str(num1 + num2)
print("The answer is" + result)
#continue next..
+ 2
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter '-' to subtract two numbers")
print("Enter '*' to multiply two numbers")
print("Enter '/' to divide two numbers")
print("Enter 'quit' to end the program")
user_input = input("input: ")
print(user_input)
if user_input == "quit":
print("This is the end")
else:
num1 = float(input("Enter a number: "))
print("num1 = " + str(num1))
num2 = float(input("Enter another number: "))
print("num2 = " + str(num2))
if user_input == "add":
result = str(num1 + num2)
elif user_input == "-":
result = str(num1 - num2)
elif user_input == "*":
result = str(num1 * num2)
elif user_input == "/":
result = str(num1 / num2)
print("The answer is " + result)
+ 1
Thanks you both