Spring naar hoofdinhoud
Recursion and trees 0 van 6 activiteiten opgelost
  1. Recursion and Trees Nog niet gelezen
  2. Recursion and Trees: quiz Nog niet gelezen
  3. Define Data Nog niet opgelost
  4. Debug Tree Nog niet opgelost
  5. Fill Tree Nog niet opgelost
  6. Evaluate Operator Nog niet opgelost
Volgende reeks Dictionaries
Recursion and trees

Evaluate Operator

Meld je aan om je oplossing in te dienen en feedback te krijgen.

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 ___