Skip to content

Commit b5b4a6f

Browse files
committed
making necessary changes based on code review
1 parent af120e7 commit b5b4a6f

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

Sprint5/classes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ def is_adult(person: Person) -> bool:
1616

1717
print(is_adult(imran))
1818

19-
def works_at(person: Person) -> str:
20-
return person.jobcompany

Sprint5/generics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class Person:
1313

1414
Sara = Person(name="Sara",age= 31, children=[Muhib, Muiz])
1515

16-
def print_family_tree(person: Person) -> None:
17-
print(person.name)
16+
def print_family_tree(person: Person, indent: int = 0) -> None:
17+
print(" " * indent + f"{person.name} ({person.age})") #indent(int)represents how many spaces to put before the person’s name when printing.
1818
for child in person.children:
19-
print(f" {child.name} ({child.age})")
19+
print_family_tree(child, indent + 2)
2020

2121
print_family_tree(Sara)

Sprint5/type.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ def sum_balances(accounts:Dict[str,int])-> int: #takes type dic[str, int}returns
1313

1414
def format_pence_as_string(total_pence: int)-> str: #type int returns type str
1515
#formatting pence as a string
16+
sign = "-" if total_pence < 0 else ""
17+
total_pence = abs(total_pence)
18+
1619
if total_pence < 100:
17-
return f"{total_pence}p"
20+
return f"{sign}{total_pence}p"
1821
pounds =(total_pence // 100) #floordivision always returns an int
1922
pence = total_pence % 100
20-
return f"£{pounds}.{pence:02d}"
23+
return f"{sign}£{pounds}.{pence:02d}"
2124

2225
balances:Dict[str,int] = { #dic type {str:int}
2326
"Sima": 700,

0 commit comments

Comments
 (0)