I need help to write this code below, the code should be in python. Thanks The I
ID: 3834812 • Letter: I
Question
I need help to write this code below, the code should be in python. Thanks The InteriorNode value() method should use the following steps: Use self._leftOperand.value() to get the value of its left operand. Use self._rightOperand.value() to get the value of its right operand. self._operator contains the operator type. The valid operator types are: "+", "-", "*", "/", and "^". Use self._operator in conditional logic to calculate the value to return. Examples: If the operator is "+" (addition), the returned value should be: value of left operand + value of right operand If the operator is "^" (exponentiation), the returned value should be: value of left operand ** value of right operand If the operator does not equal a valid value, return 0.
Explanation / Answer
def evaluate(self):
lVal = self._leftOperand.value()
rVal = self._rightOperand.value()
op = self._operator ()
if op == "+":
return lVal + rVal
elif op == "-":
return lVal - rVal
elif op == "*":
return lVal * rVal
elif op == "/":
return lVal / rVal
elif op == "^":
return lVal ** rVal
else:
return 0
Change method name as per your requirement as that was not shared.
# code link: https://paste.ee/p/FEPEK
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.