@@ -22,26 +22,29 @@ def sum_balances(accounts: dict[str, int]) -> int:
2222 total += pence
2323 return total
2424
25- # added integer type annotation and a return type of string for the output
26- def format_pence_as_string (total_pence : int ) -> str :
27- if total_pence < 100 :
28- return f"{ total_pence } p"
29- pounds = int (total_pence / 100 )
30- pence = total_pence % 100
25+ # added integer type annotation and a return type of string for the output and renamed the function
26+ # parameter to avoid shadowing issue with variable name in the outer scope
27+ def format_pence_as_string (total_pence_amount : int ) -> str :
28+ if total_pence_amount < 100 :
29+ return f"{ total_pence_amount } p"
30+ pounds = int (total_pence_amount / 100 )
31+ pence = total_pence_amount % 100
3132 return f"£{ pounds } .{ pence :02d} "
3233
33- balances = {
34+ # renamed variable from 'balances' to 'account_balances' to avoid shadowing the function parameter
35+ # 'balances' in open_account function.
36+ account_balances = {
3437 "Sima" : 700 ,
3538 "Linn" : 545 ,
3639 "Georg" : 831 ,
3740}
3841
3942# added the balances dictionary as first argument (as required above)
4043# and altered the amounts types from float 9.13 and string "7.13" to integers
41- open_account (balances , "Tobi" , 913 )
42- open_account (balances , "Olya" , 713 )
44+ open_account (account_balances , "Tobi" , 913 )
45+ open_account (account_balances , "Olya" , 713 )
4346
44- total_pence = sum_balances (balances )
47+ total_pence = sum_balances (account_balances )
4548# corrected the function name (originally was "format_pence_as_str")
4649total_string = format_pence_as_string (total_pence )
4750
0 commit comments