Calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Calculator

So my son tried to make a calculator with the help of the lessons, but the playground site isnt taking the inputs that are given. what is the problem? this is a copy of the code: 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 'raise' to raise the first number to the second number") print("Enter 'quit' to quit the program") user_input = (": ") if user_input == "quit": break elif user_input == "add": num1 = float(input("Enter a number:")) num2 = float(input("Enter a second number:")) result = str(num1 + num2) print("The aswer is" + result) elif user_input == "subtract": num3 = float(input("Enter a number:")) num4 = float(input("Enter a second number:")) esult = str(num3 - num4) print("The aswer is" + result) elif user_input == "multiply": num5 = float(input("Enter a number:")) num6 = float(input("Enter a second number:")) esult = str(num5 * num6) print("The aswer is" + result) elif user_input == "divide": num7 = float(input("Enter a number:")) num8 = float(input("Enter a second number:")) esult = str(num7 / num8) print("The aswer is" + result) elif user_input == "raise": num9 = float(input("Enter a number:")) num0 = float(input("Enter a second number:")) esult = str(num9 ** num0) print("The aswer is" + result) else: print("Unknown input")

14th Mar 2017, 7:50 AM
jonatan ekberg
jonatan ekberg - avatar
7 Answers
+ 7
Check line no 9 from top there is no input function for variable user_input
14th Mar 2017, 8:55 AM
Shirious
Shirious - avatar
+ 6
Jonathan do what Meherban Singh said
15th Mar 2017, 2:37 AM
Shirious
Shirious - avatar
+ 3
yo, replace this line :- user_input =(": ") with :- user_input=input(": ")
14th Mar 2017, 11:55 AM
Meharban Singh
Meharban Singh - avatar
+ 1
And what should be the input function? Should i replace or add something?
14th Mar 2017, 10:09 AM
jonatan ekberg
jonatan ekberg - avatar
+ 1
i am so so confused
24th Oct 2020, 12:09 AM
Jessica Hampton
Jessica Hampton - avatar
0
tnx guys :)
15th Mar 2017, 9:21 AM
jonatan ekberg
jonatan ekberg - avatar
0
Anytime bro
15th Mar 2017, 10:06 AM
Meharban Singh
Meharban Singh - avatar