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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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", None) root.children.append(Node("2", root)) root.children.append(Node("3", root)) root.children.append(Node("4", root)) 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 | 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", None) root.children.append(Node("2", root)) root.children.append(Node("3", root)) root.children.append(Node("4", root)) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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", None) root.children.append(Node("2", root)) root.children.append(Node("3", root)) root.children.append(Node("4", root)) print(str(root)) |
(1 2 2 3 3 4 4)
Testing if the previous output contains the string (1 (2 3) 4)
: 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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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 = [Node(2, root), Node(4, root)] root.children[0].children = [Node(3, root.children[0])] 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 | 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 = [Node(2, root), Node(4, root)] root.children[0].children = [Node(3, root.children[0])] print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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 = [Node(2, root), Node(4, root)] root.children[0].children = [Node(3, root.children[0])] print(str(root)) |
Traceback (most recent call last):
File "/usr/src/app/main.py", line 18, in <module>
print(str(root))
^^^^^^^^^
File "/usr/src/app/main.py", line 12, in __repr__
return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')'
~~~^~~~~~~~~~
TypeError: can only concatenate str (not "int") to str
Testing if the previous output contains the string (1 (2 3) 4)
: 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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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.append(Node('3', root)) root.children.append(Node('4', root)) 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 | 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.append(Node('3', root)) root.children.append(Node('4', root)) 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 | 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.append(Node('3', root)) root.children.append(Node('4', root)) print(str(root)) |
(1 2 2 3 3 4 4)
Testing if the previous output contains the string (1 (2 3) 4)
: 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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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.append(Node('3', root)) root.children.append(Node('4', root)) 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 | 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.append(Node('3', root)) root.children.append(Node('4', root)) print(str(root)) |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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.append(Node('3', root)) root.children.append(Node('4', root)) print(str(root)) |
(1 2 2 3 3 4 4)
Testing if the previous output contains the string (1 (2 3) 4)
: 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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
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) Call the root of the tree 'root'. Then print out str(root). DO NOT MODIFY THE Node CLASS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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') Node('2', root) Node('3', root) Node('4', root) print(str(root)) |
1 | (1 (2 3) 4) |
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 | 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') Node('2', root) Node('3', root) Node('4', root) 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 | 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') Node('2', root) Node('3', root) Node('4', root) print(str(root)) |
(1 2 3 4)
Testing if the previous output contains the string (1 (2 3) 4)
: False