Skip to content

Commit e437bab

Browse files
committed
Running the code through mypy, and fix all of the bugs that show up
1 parent 4b082ac commit e437bab

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
def open_account(balances: dict[str, int], name: str, amount: int):
3+
balances[name] = amount
4+
5+
6+
def sum_balances(accounts: dict[str, int]) -> int:
7+
total = 0
8+
for name, pence in accounts.items():
9+
print(f"{name} had balance {pence}")
10+
total += pence
11+
return total
12+
13+
14+
def format_pence_as_string(total_pence: int) -> str:
15+
if total_pence < 100:
16+
return f"{total_pence}p"
17+
pounds = int(total_pence / 100)
18+
pence = total_pence % 100
19+
return f"£{pounds}.{pence:02d}"
20+
21+
22+
balances: dict[str, int] = {
23+
"Sima": 700,
24+
"Linn": 545,
25+
"Georg": 831,
26+
}
27+
28+
29+
open_account(balances, "Tobi", 913)
30+
open_account(balances, "Olya", 713)
31+
32+
total_pence = sum_balances(balances)
33+
total_string = format_pence_as_string(total_pence)
34+
35+
print(f"The bank accounts total {total_string}")

0 commit comments

Comments
 (0)