Skip to content

Instantly share code, notes, and snippets.

@CCLDArjun
Created June 2, 2021 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CCLDArjun/4bf6aadb18c85b1274efd179d4a8acc2 to your computer and use it in GitHub Desktop.
Save CCLDArjun/4bf6aadb18c85b1274efd179d4a8acc2 to your computer and use it in GitHub Desktop.
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