I need help with returning the value of expression(expression being the parameter of the function).
This is what i have tried so far. It's just an example with a random equation, my plan would be to understand how to solve it correctly so i could later on tranform it into a function
sum = 0
eq = '2+4-5'
string = ""
for x in eq:
if x in ('+', '-'):
if x == '+':
sum += int(string)
elif x == "-":
sum -= int(string)
string = ""
else:
string += x
sum += int(string)
print(sum)
"1+2" => 3 # input = "1+2" and the output of the function would be 3
"-1+21" => 20
"+1-1" => 0