My very simple calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

My very simple calculator

I wrote, configured, and debugged code for a calculator with eventual success. I posted it to this website and have found that it doesn't operate properly. Perhaps because it is an interpreter? Clarification on this issue and how it can remedied would be greatly appreciated. Perhaps with better constructed code - although I find it pleasantly done? Here is the code: (Copy/paste into new document in IDLE and run; it works. Copy/paste into Interpreter; results in error.) print('I shall compute your mathematical equation!') while True: user_operation = input('Please type and enter what operation you would like to perform: \n Addition \n Subtraction \n Multiplication \n Division \n \n ...or \n Quit to exit.\n') if user_operation in ('Quit','quit'): print('Closing...') break elif user_operation not in ('Addition','addition','+','Subtraction','subtraction','-','Multiplication','multiplication','x','*','Division','division','/'): print('Invalid input! Please try again!') continue else: user_num1 = int(input('What is your first number?')) user_num2 = int(input('What is your second number?')) if user_operation in ('Addition','addition','+'): addsum = str(user_num1 + user_num2) print('Your result is ' +addsum+ ' !') elif user_operation in ('Multiplication', 'multiplication','x','*'): addsum = str(user_num1 * user_num2) print('Your result is ' +addsum+ ' !') elif user_operation in ('Subtraction','subtraction','-'): addsum = str(user_num1 - user_num2) print('Your result is ' +addsum+ ' !') elif user_operation in ('Division','division','/'): addsum = str(user_num1 / user_num2) print('Your result is ' +addsum+ ' !') quit() Thanks in advance.

26th Apr 2018, 7:53 AM
Andrew Mann
Andrew Mann - avatar
4 Answers
29th Apr 2018, 3:18 PM
Programmer Gaurav
Programmer Gaurav - avatar
+ 1
I wrote simple one line calculator in python https://code.sololearn.com/c7vcE67jvGGi/?ref=app
26th Apr 2018, 10:12 AM
Rishi Kumar.S
Rishi Kumar.S - avatar
0
@Rishi Lacks dealing with improper input, but otherwise, it's a great code. Good job. ^-^
26th Apr 2018, 11:12 AM
Andrew Mann
Andrew Mann - avatar
0
Note: I edited it to be shorter by adding the print result statement after the elif calculation statements, therefore eliminating the need to have one in each elif statement.
26th Apr 2018, 11:19 AM
Andrew Mann
Andrew Mann - avatar