424,972 Members | 883 Online Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Python Calculator not accepting proper operations

 P: 2 I was trying to make a advanced calculator in Python. The calculator had been working fine until I added my "operation" variable. I am unsure if this has to do with my computer running Linux Mint Mate as it's OS. I have checked through my code multiple times and couldn't find anything wrong with it "Note: I am mildly new to Python and have only been learning it for about a month" When the user tries to enter a operation, it responds with: Expand|Select|Wrap|Line Numbers Traceback (most recent call last):   File "pythoncalculator.py", line 7, in      ''')   File "", line 1     +     ^ SyntaxError: unexpected EOF while parsing If the user enters a whole equation then it will give them the option to enter the numbers that are going to be used in the equation. When the user does this they get: Expand|Select|Wrap|Line Numbers Please enter the math operation you want to do:  + Add  - Subtract  * Multiply  / Divide   5 + 5 Enter first number: 5 Enter second number: 5 You have failed to type in a proper operation. Please restart program. This shows that it does recognize that the number is not a choice for the operation, but when a proper answer choice is entered it will not work "See the Syntax Error above to know what happens" I have also included a large portion of my code, if anyone can see whats wrong please respond. Expand|Select|Wrap|Line Numbers operation = input(''' Please enter the math operation you want to do:  + Add  - Subtract  * Multiply  / Divide   ''') num1 = int(input('Enter first number: ')) num2 = int(input('Enter second number: '))   if operation == '+':     print('{} + {} = '.format(num1, num2))     print(num1 + num2)   elif operation == '-':     print('{} - {} = '.format(num1, num2))     print(num1 - num2)   elif operation == '*':     print('{} * {} = '.format(num1, num2))     print(num1 * num2)   elif operation == '/':     print('{} / {} = '.format(num1, num2))     print(num1 / num2)   May 1 '17 #1

The error message there are triple quotes after the 3

Expand|Select|Wrap|Line Numbers
1.   File "pythoncalculator.py", line 7, in <module>
2.     ''')
3.                          3     ''') <-----
and then you continue with 4 on the next line, which is not part of the literal anymore since it ended on the "3 option" line above it. 