forked from markmbadham/pythoncourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts001.py
36 lines (29 loc) · 921 Bytes
/
accounts001.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
class Account(object):
accounts = 0
def __init__(self,balance=0):
self.balance = balance
Account.accounts += 1
self.accno = Account.accounts
def debit(self,amount):
self.balance -= amount
def credit(self,amount):
self.balance += amount
class CreditAccount(Account):
def __init__(self,balance=0, credit_limit=0):
Account.__init__(self,balance)
self.credit_limit=credit_limit
def debit(self,amount):
assert amount < self.balance + self.credit_limit, 'account overdrawn'
Account.debit(self,amount)
def show_accounts(acc):
print(acc.accno,acc.balance)
print(acc.__class__)
print(isinstance(acc,Account))
print(isinstance(acc,CreditAccount))
acc1 = Account(1000)
acc1.debit(30)
acc2 = CreditAccount(300,100)
acc2.credit(50)
acc2.debit(500)
for a in (acc1,acc2): show_accounts(a)
print(acc2.credit_limit)