+ 1

I made a program of calculator in PYTHON 3, but showing traceback error.

I have made a Simple calculator programing by python 3. But It is showing traceback error. I couldn't find the mistake. Someone please help me out. Here is the code below - while True : print ('Simple Calculator') print ('Options') print ('Enter add for addition') print ('Enter sub for subtract') print ('Enyer mult for multifunction') print ('Enter dev for division') num_1 = float (input ('Enter a number')) num_2 = float (input ('Enter another number')) if user_input == 'add': result = str(num_1 + num_2) print ('Answer: ' + result ) elif user_input == 'sub': result = str(num_1 - num_2) print ('Answer: ' + result ) elif user_input == 'mult': result = str (num_1 * num_2) print('Answer: '+result) elif user_input == 'dev': result = str(num_1 / num_2 ) print ('Answer: '+result) https://code.sololearn.com/cE8d7gvX0hCY/?ref=app

18th Apr 2020, 7:24 PM
Surojit Mondal
Surojit Mondal - avatar
3 Antworten
+ 3
as addition to William M Instead of while True: while user_input != "quit": That helps a bit but u still have to enter add 2 3 sub 5 4 quit
18th Apr 2020, 8:23 PM
Oma Falk
Oma Falk - avatar
+ 2
Just define user_input, you wrote "if user_input" but you did not define user_input. Just write before num_1, user_input = input(). But... you will still get an error. Why? Because in solo learn you can just give an input one time. If you want to repare it remove while. While-loop would just work on your pc.
18th Apr 2020, 8:12 PM
William M
William M - avatar
18th Apr 2020, 8:30 PM
Richard Strong
Richard Strong - avatar