You are required to implement a simple symbolic equation solver. The equation should be stored in a binary tree. An equation consists of operands and operators. Each operand or operator should be stored as a tuple of the form (TYPE, VALUE). Examples are (OPERAND, 5), (OPERAND, 7), (OPERAND, 34), (OPERATOR, ‘+’) or (OPERATOR, '*’'). Following operators should be supported: addition (+), subtraction (-), multiplication (*), and exponentiation (^). Grouping of terms in the equation using brackets should be supported. However, nested brackets need not be supported.
def sym_maths(m,n):
m = input('Enter the operator: ')
n = int(input("Enter the operand: "))
operand1 = int(input("Enter the second operand"))
if m == '+':
return n+operand
elif m == '*':
return n*operand
elif m == '-':
return n-operand
else:
return n**operand
Comments
Leave a comment