I am writing a program to take an equation from the user for example 2 * 56
and the program gives out the answer. this is working but for more than 2 function my code breaks
equation = input('Enter an equation: ')
def addition():
splited = equation.split('+')
results = [float(i) for i in splited]
results = results[0] + results[1]
print(results)
def subtraction():
splited= equation.split('-')
results = [float(i) for i in splited]
results = results[0] - results[1]
print(results)
def multiply():
splited= equation.split('*')
results = [float(i) for i in splited]
results = results[0] * results[1]
print(results)
def divide():
splited= equation.split('/')
results = [float(i) for i in splited]
results = results[0] / results[1]
print(results)
if ('+') in equation:
addition()
elif ('-') in equation:
subtraction()
elif ('*') in equation:
multiply()
elif ('/') in equation:
divide()
else:
print('Error! Please only input + , - , * , /')
this code easily works for equations containing only one operation but what if user inputs 2 + 2 - 9 * 6
how can i modify this code to work with every case possible