Skip to content

Commit 024601f

Browse files
Add files via upload
1 parent 35bb20d commit 024601f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.

0 commit comments

Comments
 (0)