Skip to content

Commit b5c1ee6

Browse files
committed
Completed task 2-type checking with mypy
1 parent 6c16e45 commit b5c1ee6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Dict
2+
3+
def open_account(balances: Dict[str, int], name: str, amount: int)-> None:
4+
balances[name] = amount
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+
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+
balances = {
21+
"Sima": 700,
22+
"Linn": 545,
23+
"Georg": 831,
24+
}
25+
26+
open_account(balances, "Tobi", 913)
27+
open_account(balances, "Olya", 713)
28+
29+
total_pence = sum_balances(balances)
30+
31+
print(f"The bank accounts total {total_string}")

0 commit comments

Comments
 (0)