Question: and here is what I have on the problem3 class Node: def __init__(self, value, children): self.value = value self.children = children extree = Node(1, [Node(2,[]),
and here is what I have on the problem3
class Node: def __init__(self, value, children): self.value = value self.children = children extree = Node(1, [Node(2,[]), Node(3, [Node(4, [Node(5, []), Node(6, [Node(7, [])])])])]) def recSumNodes(node): total = node.value for child in node.children: total += recSumNodes(child) return total
Objective: Suppose you are given a tree. Write a function treeToString(root) which constructs a string with the values at each level of the tree on a new line. For example, using exTree from Problem 3. we would see the following: print(treeToString(exfree)) > > 23 2 40 > 56 > 7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
