Skip to main content
Recursion and trees 0 of 6 activities solved
  1. Recursion and Trees Not yet read
  2. Recursion and Trees: quiz Not yet read
  3. Define Data Not yet solved
  4. Debug Tree Not yet solved
  5. Fill Tree Not yet solved
  6. Evaluate Operator Not yet solved
Next series Dictionaries
Recursion and trees

Evaluate Operator

Sign in to hand in your solution and get feedback.

from dataclasses import dataclass @dataclass class Expression: pass @dataclass class BinaryExpression(Expression): operator: str left: Expression right: Expression @dataclass class IntegerExpression(Expression): value: int ###### Edit below ################################################################# def evaluate_math(expression: Expression) -> int: if isinstance(expression, IntegerExpression): # In this base case, you *know* that expression is an IntegerExpression! return ___ # In this recursive case, you *know* that expression is a BinaryExpression! # ... # ... Replace these comments with the real code! # ... return ___