Skip to content

Commit 625be12

Browse files
committed
generics task
1 parent 49fae75 commit 625be12

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

sprint-5/generics_exercise.py

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

0 commit comments

Comments
 (0)