class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') root.children.append(Node('2', root)) root.children[0].children.append(Node('3', root.children[0])) root.children[0].children.append(Node('4', root.children[0])) root.children[0].children.append(Node('5', root.children[0])) root.children[0].children.append(Node('6', root.children[0])) root.children[0].children.append(Node('7', root.children[0])) root.children[0].children.append(Node('8', root.children[0])) root.children.append(Node('9', root)) root.children[1].children.append(Node('10', root.children[1])) root.children[1].children.append(Node('11', root.children[1])) root.children[1].children.append(Node('12', root.children[1])) print(str(root)) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') root.children.append(Node('2', root)) root.children[0].children.append(Node('3', root.children[0])) root.children[0].children.append(Node('4', root.children[0])) root.children[0].children.append(Node('5', root.children[0])) root.children[0].children.append(Node('6', root.children[0])) root.children[0].children.append(Node('7', root.children[0])) root.children[0].children.append(Node('8', root.children[0])) root.children.append(Node('9', root)) root.children[1].children.append(Node('10', root.children[1])) root.children[1].children.append(Node('11', root.children[1])) root.children[1].children.append(Node('12', root.children[1])) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') root.children.append(Node('2', root)) root.children[0].children.append(Node('3', root.children[0])) root.children[0].children.append(Node('4', root.children[0])) root.children[0].children.append(Node('5', root.children[0])) root.children[0].children.append(Node('6', root.children[0])) root.children[0].children.append(Node('7', root.children[0])) root.children[0].children.append(Node('8', root.children[0])) root.children.append(Node('9', root)) root.children[1].children.append(Node('10', root.children[1])) root.children[1].children.append(Node('11', root.children[1])) root.children[1].children.append(Node('12', root.children[1])) print(str(root)) |
(1 (2 3 3 4 4 5 5 6 6 7 7 8 8 10 10 11 11 12 12) (2 3 3 4 4 5 5 6 6 7 7 8 8 10 10 11 11 12 12) 9 9)
Testing if the previous output contains the string (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))
: False
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' if __name__ == '__main__': root = Node('1') node2 = Node('2', root) node3 = Node('3', node2) node4 = Node('4', node2) node5 = Node('5', node2) node6 = Node('6', node2) node7 = Node('7', node2) node8 = Node('8', node2) node9 = Node('9', root) node10 = Node('10', root) node11 = Node('11', node10) node12 = Node('12', node10) print(str(root)) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' if __name__ == '__main__': root = Node('1') node2 = Node('2', root) node3 = Node('3', node2) node4 = Node('4', node2) node5 = Node('5', node2) node6 = Node('6', node2) node7 = Node('7', node2) node8 = Node('8', node2) node9 = Node('9', root) node10 = Node('10', root) node11 = Node('11', node10) node12 = Node('12', node10) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' if __name__ == '__main__': root = Node('1') node2 = Node('2', root) node3 = Node('3', node2) node4 = Node('4', node2) node5 = Node('5', node2) node6 = Node('6', node2) node7 = Node('7', node2) node8 = Node('8', node2) node9 = Node('9', root) node10 = Node('10', root) node11 = Node('11', node10) node12 = Node('12', node10) print(str(root)) |
(1 (2 3 4 5 6 7 8) 9 (10 11 12))
Testing if the previous output contains the string (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))
: False
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') n1 = Node('2', root) n2 = Node('9', root) n3 = Node('10', n2) n4 = Node('11', n3) n5 = Node('12', n3) n6 = Node('3', n1) n7 = Node('4', n1) n8 = Node('5', n1) n9 = Node('6', n1) n10 = Node('7', n1) n11 = Node('8', n1) print(str(root)) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') n1 = Node('2', root) n2 = Node('9', root) n3 = Node('10', n2) n4 = Node('11', n3) n5 = Node('12', n3) n6 = Node('3', n1) n7 = Node('4', n1) n8 = Node('5', n1) n9 = Node('6', n1) n10 = Node('7', n1) n11 = Node('8', n1) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') n1 = Node('2', root) n2 = Node('9', root) n3 = Node('10', n2) n4 = Node('11', n3) n5 = Node('12', n3) n6 = Node('3', n1) n7 = Node('4', n1) n8 = Node('5', n1) n9 = Node('6', n1) n10 = Node('7', n1) n11 = Node('8', n1) print(str(root)) |
(1 (2 3 4 5 6 7 8) (9 (10 11 12)))
Testing if the previous output contains the string (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))
: False
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node("1") two = Node("2", root) three = Node("3", two) four = Node("4", two) five = Node("5", two) six = Node("6", two) seven = Node("7", two) eight = Node("8", two) nine = Node("9", root) ten = Node("10", root) eleven = Node("11", ten) twelve = Node("12", ten) print(str(root)) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node("1") two = Node("2", root) three = Node("3", two) four = Node("4", two) five = Node("5", two) six = Node("6", two) seven = Node("7", two) eight = Node("8", two) nine = Node("9", root) ten = Node("10", root) eleven = Node("11", ten) twelve = Node("12", ten) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node("1") two = Node("2", root) three = Node("3", two) four = Node("4", two) five = Node("5", two) six = Node("6", two) seven = Node("7", two) eight = Node("8", two) nine = Node("9", root) ten = Node("10", root) eleven = Node("11", ten) twelve = Node("12", ten) print(str(root)) |
(1 (2 3 4 5 6 7 8) 9 (10 11 12))
Testing if the previous output contains the string (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))
: False
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' Write a complete python file that will print the tree (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12))) Call the root of the tree 'root'. Then print out str(root).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') root.children.append(Node('2', root)) root.children[0].children.extend(Node(str(i), root.children[0]) for i in range(3, 9)) root.children.append(Node('9', root)) root.children[1].children.extend(Node(str(i), root.children[1]) for i in range(10, 13)) print(str(root)) |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') root.children.append(Node('2', root)) root.children[0].children.extend(Node(str(i), root.children[0]) for i in range(3, 9)) root.children.append(Node('9', root)) root.children[1].children.extend(Node(str(i), root.children[1]) for i in range(10, 13)) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Node: def __init__(self, name, parent=None): self.name = name self.parent = parent self.children = [] if parent: self.parent.children.append(self) def __repr__(self): if self.children == []: return self.name return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')' root = Node('1') root.children.append(Node('2', root)) root.children[0].children.extend(Node(str(i), root.children[0]) for i in range(3, 9)) root.children.append(Node('9', root)) root.children[1].children.extend(Node(str(i), root.children[1]) for i in range(10, 13)) print(str(root)) |
(1 (2 3 3 4 4 5 5 6 6 7 7 8 8 10 10 11 11 12 12) (2 3 3 4 4 5 5 6 6 7 7 8 8 10 10 11 11 12 12) 9 9)
Testing if the previous output contains the string (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))
: False