Skip to content

Commit 1cecb6e

Browse files
author
Fatma Degirmenci
committed
Make family tree recursive
1 parent 248a52a commit 1cecb6e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

sprint5/generics.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class Person:
1212

1313
imran = Person(name="Imran", age=40,children=[fatma, aisha])
1414

15-
def print_family_tree(person: Person) -> None:
16-
print(person.name)
15+
def print_family_tree(person: Person, level:int=0) -> None:
16+
indent="-->" * level
17+
print(f"{indent}{person.name} ({person.age})")
1718
for child in person.children:
18-
print(f"- {child.name} ({child.age})")
19+
print_family_tree(child,level+1)
1920

2021
print_family_tree(imran)

0 commit comments

Comments
 (0)