Skip to content

Commit 83804ee

Browse files
committed
Update my code and Fix bugs to pass mypy type checking
1 parent 664b191 commit 83804ee

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

prep_exercise/2_type_checking_with_mypy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11

2-
def open_account(balances, name, amount):
2+
def open_account(balances: dict[str, int], name: str, amount: int) -> None:
33
balances[name] = amount
44

5-
def sum_balances(accounts):
5+
def sum_balances(accounts: dict[str, int]) -> int:
66
total = 0
77
for name, pence in accounts.items():
88
print(f"{name} had balance {pence}")
9-
total += int(pence)
9+
total += pence
1010
return total
1111

12-
def format_pence_as_string(total_pence):
12+
def format_pence_as_string(total_pence: int) -> str:
1313
if total_pence < 100:
1414
return f"{total_pence}p"
15-
pounds = int(total_pence / 100)
15+
pounds = total_pence // 100
1616
pence = total_pence % 100
1717
return f"£{pounds}.{pence:02d}"
1818

1919
balances = {
2020
"Sima": 700,
2121
"Linn": 545,
22-
"Georg": 831,
22+
"George": 831,
2323
}
2424

2525
open_account(balances, "Tobi", 913)
26-
open_account(balances, "Olya", "713")
26+
open_account(balances, "Olya", 713)
2727

2828
total_pence = sum_balances(balances)
2929
total_string = format_pence_as_string(total_pence)

0 commit comments

Comments
 (0)