Quote:
I am making a project in python. It is a prefix calculator that takes in multiple operands and multiple operators.
No matter the details, evaluating a mathematical expression involve a recursive approach in a fashion or another.
The expression is made of an arbitrary number of elements and evaluating it consist of repeatedly find a triplet (operator, number, number) and replace it by its result until there is no more triplet. You duty is to design the code accordingly.
+ 1 + 2 4 => + 1 6 => 7
+ + 1 2 4 => + 3 4 => 7
This code is recursive when a simple loop is enough:
def repeat():
x = input("Enter calculation in prefix notation: ")
y = prefix(x)
print(y)
if y == "x":
print("Goodbye")
else:
repeat()