-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.py
More file actions
75 lines (48 loc) · 1.42 KB
/
Copy pathclasses.py
File metadata and controls
75 lines (48 loc) · 1.42 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Account:
interest = 0.04
def __init__(self, account_holder):
self.balance = 0
self.holder = account_holder
def deposit(self, amount):
self.balance = self.balance + amount
return self.balance
kirk_acc = Account('Kirk')
spock_acc = Account('Spock')
spock_acc.balance = 200
accounts = (kirk_acc, spock_acc)
[acc.balance for acc in accounts]
kirk_acc.interest = 0.5
Account.interest = 0.3
print(spock_acc.interest)
Account.deposit(spock_acc, 150)
print(kirk_acc.interest)
# extending from class
class Account:
interest = 0.04
def __init__(self, account_holder):
self.balance = 0
self.holder = account_holder
def deposit(self, amount):
self.balance = self.balance + amount
return self.balance
def withdraw(self, amount):
if amount > self.balance:
return 'Insufficient found'
self.balance -= amount
return self.balance
class CheckingAccount(Account):
interest = 0.01
withdraw_fee = 1
def withdraw(self, amount):
return Account.withdraw(self, amount + self.withdraw_fee)
spock_acc = Account('Spock')
spock_acc.balance = 200
spock_acc.interest = 0.5
kirk_acc = CheckingAccount('Kirk')
Account.interest = 0.3
print(spock_acc.interest)
print(kirk_acc.interest)
kirk_acc.deposit(200)
kirk_acc.withdraw(5)
kirk_acc.withdraw_fee = 0.5
kirk_acc.withdraw(10)