Created
June 2, 2021 02:21
-
-
Save CCLDArjun/4bf6aadb18c85b1274efd179d4a8acc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expression = input('Enter a simple math expression: ') | |
if expression.find(' ') == 1: | |
expression = expression.split() | |
expression = str(expression[0]+expression[1]+expression[2]) | |
possibleOperations = ['+', '-', '/', '*'] | |
for operation in possibleOperations: | |
if expression.find(operation) == 1: | |
if operation == '+': | |
expression = expression.split(operation) | |
print('The answer is {}'.format(float(expression[0]) + float(expression[1]))) | |
break | |
if operation == '-': | |
expression = expression.split(operation) | |
print('The answer is {}'.format(float(expression[0]) - float(expression[1]))) | |
break | |
if operation == '/': | |
expression = expression.split(operation) | |
print('The answer is {}'.format(float(expression[0]) / float(expression[1]))) | |
break | |
if operation == '*': | |
expression = expression.split(operation) | |
print('The answer is {}'.format(float(expression[0]) * float(expression[1]))) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment