You are required to implement a simple equation stored in a binary tree.
Each operand or operator should be stored as a tuple of the form (TYPE, VALUE).
Your task is to complete the body of the functions, insert and evaluate.
The parameter data will be used to store the tuple (e.g. (OPERAND,34)
bracketed in the insert function is used to denote whether an operator is
The evaluate function should be able to process the expression stored in the binary tree and compute the final result.To do that,the function should be able to traverse the binary tree. Observe how the evaluate function is used inside the get ouput.
the expression stored in the binary tree is“1+(2*3)+3^ 2"
the evaluate function should return 100.
The get_output function returns the final result
function) if it is in the range [0, 999]. If the final result is less than 0, it returns
UNDERFLOW and if the final result is greater than 999, it returns OVERFLOW.
def sym_maths(x,y):
list1 = ['+', '-', '*', '^']
input1 = input('Enter operator here: ')
if input1 == '+':
return x+y
elif input1 == '*':
return x * y
elif input1 == '-':
return x-y
else:
return x**y
Comments
Leave a comment