File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ class BankAccount :
2+ def __init__ (self , account_number , balance ):
3+ self .account_number = account_number
4+ self .balance = balance
5+
6+ def __repr__ (self ):
7+ return f"{ type (self ).__name__ } ({ self .account_number } , { self .balance } )"
8+
9+ def _verify_funds (self , amount ):
10+ return self .balance >= amount
11+
12+ def _deduct_funds (self , amount ):
13+ self .balance -= amount
14+
15+ def _add_funds (self , amount ):
16+ self .balance += amount
17+
18+ def get_balance (self ):
19+ return self .balance
20+
21+ def withdraw (self , amount ):
22+ if self ._verify_funds (amount ):
23+ self ._deduct_funds (amount )
24+ return True
25+ return False
26+
27+ def deposit (self , amount ):
28+ self ._add_funds (amount )
29+ return True
Original file line number Diff line number Diff line change 1+ # Poorly-named function, parameter, and variable
2+ def init (n ):
3+ return " " .join (f"{ i [0 ]} ." for i in n .split ())
4+
5+
6+ # Descriptive names improve readability
7+ def get_initials (full_name ):
8+ return " " .join (f"{ name [0 ]} ." for name in full_name .split ())
9+
10+
11+ print (get_initials ("James Clerk Maxwell" ))
12+ # OUTPUT: J. C. M.
13+ print (get_initials ("Richard Feynman" ))
14+ # OUTPUT: R. F.
You can’t perform that action at this time.
0 commit comments