Answer to Question #257904 in Python for NeroTamil

Question #257904

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.


1
Expert's answer
2021-10-28T01:22:54-0400
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

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