File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ def open_account (balances , name , amount ): #dic type str and int
2+ balances [name ] = amount
3+
4+ def sum_balances (accounts ): #takes type dic[str, int}returns int
5+ total = 0
6+ for name , pence in accounts .items ():
7+ print (f"{ name } had balance { pence } " )
8+ total += pence
9+ return total
10+
11+ def format_pence_as_string (total_pence ): #type int returns type str
12+ if total_pence < 100 :
13+ return f"{ total_pence } p"
14+ pounds = int (total_pence / 100 )
15+ pence = total_pence % 100
16+ return f"£{ pounds } .{ pence :02d} "
17+
18+ balances = { #dic type {str:int}
19+ "Sima" : 700 ,
20+ "Linn" : 545 ,
21+ "Georg" : 831 ,
22+ }
23+
24+ open_account ("Tobi" , 9.13 ) # balances not passed, amount should be an int and not a float/ string
25+ open_account ("Olya" , "£7.13" )
26+
27+ total_pence = sum_balances (balances ) #returntype int
28+ total_string = format_pence_as_str (total_pence ) #returntype str and wrong function name
29+
30+ print (f"The bank accounts total { total_string } " )
You can’t perform that action at this time.
0 commit comments