0

Where am i wrong its showing an error

def user_input(): while True: 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) elif user_input == 'multiply': num1 = float(input("enter a number: ")) num2 = float(input("enter another number: ")) result = str(num1 * num2) elif user_input == 'divide': num1 = float(input("enter a number: ")) num2 = float(input("enter another number: ")) result = str(num1 // num2) else: print("unknown input")

26th Aug 2019, 11:54 PM
K8l3 🎻
K8l3 🎻 - avatar
1 Odpowiedź
+ 1
Here, fixed: def calculator(): user_input ='' while True: user_input=input('Enter add/subtract/multiply/divide or quit: \n') 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(result) elif user_input == 'multiply': num1 = float(input("enter a number: ")) num2 = float(input("enter another number: ")) result = str(num1 * num2) print(result) elif user_input == 'divide': num1 = float(input("enter a number: ")) num2 = float(input("enter another number: ")) result = str(num1 // num2) print(result) else: print("unknown input"
27th Aug 2019, 12:20 AM
Vanwolf
Vanwolf - avatar