Skip to content

Commit ea186be

Browse files
committed
make the func print_family_tree print recursively
1 parent 750d9b2 commit ea186be

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

prep-exercises/exercise_nine.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ class Person:
88
age: int
99
children: List["Person"]
1010

11+
#Add a grandchild to the main object imran
12+
khaled = Person(name="Khaled", age=6, children=[])
13+
1114
#Add "age" field and thier respective values to "fatma" and "aisha" - instances of class "Person"
1215
fatma = Person(name="Fatma", age=14, children=[])
13-
aisha = Person(name="Aisha",age=22, children=[])
16+
aisha = Person(name="Aisha",age=22, children=[khaled])
1417

1518
##Add "age" field and its values to "imran" - instance of class "Person"
1619
imran = Person(name="Imran", age=44, children=[fatma, aisha])
@@ -19,6 +22,7 @@ def print_family_tree(person: Person) -> None:
1922
print(person.name)
2023
for child in person.children:
2124
print(f"- {child.name} ({child.age})")
25+
print_family_tree(child)
2226

2327
print_family_tree(imran)
2428

0 commit comments

Comments
 (0)