Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
Python exercise
Debug Tree
Sign in to hand in your solution and get feedback.
from dataclasses import dataclass
from bakery import assert_equal
@dataclass
class Tree:
pass
@dataclass
class BinaryTree:
value: int
left: ___
right: Tree
EMPTY = BinaryTree()
def add_up_tree(tree: Tree) -> int:
if tree == EMPTY:
return 0
left_side = tree.left
right_side = add_up_tree(tree.right)
combined = left_side + right_side
return 'value' + combined
assert_equal(add_up_tree(BinaryTree(7, EMPTY, EMPTY)), 7)
assert_equal(add_up_tree(BinaryTree(7, BinaryTree(3, EMPTY, EMPTY), EMPTY)), 10)
assert_equal(add_up_tree(BinaryTree(7, BinaryTree(3, BinaryTree(1, EMPTY, EMPTY), EMPTY), BinaryTree(9, EMPTY, EMPTY))), 20)
assert_equal(add_up_tree(EMPTY), 0)