File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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 } " )
You can’t perform that action at this time.
0 commit comments