forked from krother/advanced_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
savings_account.py
53 lines (36 loc) · 1 KB
/
savings_account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Example for classes, properties and inheritance
Exercise:
1) make the balance a property as well.
2) make it impossible for the interest rate to go above 20%
"""
from account import Account
class SavingsAccount(Account):
prefix = 'SAVINGS:'
def __init__(self, newname, interest):
super().__init__(newname, 0)
self.__interest = interest
@property
def interest_rate(self):
return self.__interest
@interest_rate.setter
def interest_rate(self, interest):
self.__interest = interest
def add_interest(self):
self.balance *= self.interest_rate
def withdraw(self, amount):
print('**extra identification step approved**')
super().withdraw(amount)
if __name__ == '__main__':
b = SavingsAccount('Betty', interest=1.03)
print(b)
b.deposit(100)
print(b)
b.withdraw(50)
print(b)
b.add_interest()
print(b)
b.interest_rate = 1.06
b.add_interest()
print(b)
# print(b.__interest)