Skip to content

Commit 150faad

Browse files
committed
type_checking.py
1 parent 5a9622a commit 150faad

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)