Skip to content

Commit 87f4a2e

Browse files
committed
exercise 9 completed
1 parent 8922e28 commit 87f4a2e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from dataclasses import dataclass
2+
from typing import List
3+
4+
@dataclass(frozen=True)
5+
class Person:
6+
name: str
7+
children: List["Person"]
8+
age: int
9+
10+
fatma = Person(name="Fatma", children=[], age=82)
11+
aisha = Person(name="Aisha", children=[], age=83)
12+
13+
imran = Person(name="Imran", children=[fatma, aisha], age=102)
14+
15+
def print_family_tree(person: Person) -> None:
16+
print(person.name)
17+
for child in person.children:
18+
print(f"- {child.name} ({child.age})")
19+
20+
print_family_tree(imran)
21+
22+
# Fix the above code so that it works.
23+
# You must not change the print on line 17 - we do want to print the children’s ages.
24+
# (Feel free to invent the ages of Imran’s children.)

0 commit comments

Comments
 (0)