Answer to Question #259332 in Python for Jauani

Question #259332

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.

1
Expert's answer
2021-10-31T12:01:56-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog