-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy path6_fix_code.py
More file actions
25 lines (19 loc) · 698 Bytes
/
6_fix_code.py
File metadata and controls
25 lines (19 loc) · 698 Bytes
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
# ✍️exercise
# Fix the above code so that it works. You must not change the print
# on line 17 - we do want to print the children’s ages.
# (Feel free to invent the ages of Imran’s children.)
from dataclasses import dataclass
from typing import List
@dataclass(frozen=True)
class Person:
name: str
age: int
children: List["Person"]
fatma = Person(name="Fatma", age=12, children=[])
aisha = Person(name="Aisha", age=25, children=[])
imran = Person(name="Imran", age=67, children=[fatma, aisha])
def print_family_tree(person: Person) -> None:
print(person.name)
for child in person.children:
print(f"- {child.name} ({child.age})")
print_family_tree(imran)