Skip to content

Commit 87cd1e2

Browse files
committed
MyType
1 parent f81a6d0 commit 87cd1e2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

type/myType.py

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

0 commit comments

Comments
 (0)