Skip to content

Commit 2223fb7

Browse files
authored
Enhance print_family_tree with indentation
Updated print_family_tree to include indentation and level.
1 parent 4cd0d89 commit 2223fb7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

prep-sprint5/generics.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class Person:
1313
imran = Person(name="Imran", age=50, children=[fatma, aisha])
1414
maria = Person(name="maria", age=38,children=[fatma])
1515

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

21-
print_family_tree(maria)
23+
print_family_tree(maria)

0 commit comments

Comments
 (0)