1+ from typing import Dict
2+
3+ # Added Type Annotations
4+ def open_account (balances : Dict [str , int ], name : str , amount : int ) -> None :
5+ balances [name ] = amount
6+
7+ def sum_balances (accounts : Dict [str , int ]) -> int :
8+ total = 0
9+ for name , pence in accounts .items ():
10+ print (f"{ name } had balance { pence } " )
11+ # If 'pence' isn't an int, this will fail or cause issues later
12+ total += pence
13+ return total
14+
15+ def format_pence_as_string (total_pence : int ) -> str :
16+ if total_pence < 100 :
17+ return f"{ total_pence } p"
18+ # Use // for floor division to ensure 'pounds' is an int
19+ pounds = total_pence // 100
20+ pence = total_pence % 100
21+ return f"£{ pounds } .{ pence :02d} "
22+
23+ balances : Dict [str , int ] = {
24+ "Sima" : 700 ,
25+ "Linn" : 545 ,
26+ "Georg" : 831 ,
27+ }
28+
29+ # BUGS FIXED HERE:
30+ # Changed 9.13 (float) to 913 (int)
31+ # Changed "£7.13" (str) to 713 (int)
32+ open_account (balances , "Tobi" , 913 )
33+ open_account (balances , "Olya" , 713 )
34+
35+ total_pence = sum_balances (balances )
36+
37+ # BUG FIXED HERE: Corrected the function name call
38+ total_string = format_pence_as_string (total_pence )
39+
40+ print (f"The bank accounts total { total_string } " )
0 commit comments