14-1
class Bankcount:
def __init__(self,countname,countnum):
self.countname = countname
self.countnum = countnum
self.balance = 0.0
def __str__(self):
msg = "your countname is " + self.countname + "\n"\
"your countnum is " + self.countnum + "\n"\
"your balance is " + str(self.balance)
return msg
def Balance(self):
print(self.balance)
def AddMoney(self,money):
self.balance += money
def TakeMoney(self,money):
if money > self.balance:
print("sorry,you balance is not satified")
else:
self.balance -= money
mycount = Bankcount("peng","19920402")
mycount.AddMoney(100)
mycount.TakeMoney(20)
print(mycount)
14-2
class Bankcount:
def __init__(self,countname,countnum):
self.countname = countname
self.countnum = countnum
self.balance = 0.0
def __str__(self):
msg = "your countname is " + self.countname + "\n"\
"your countnum is " + self.countnum + "\n"\
"your balance is " + str(self.balance)
return msg
def Balance(self):
print(self.balance)
def AddMoney(self,money):
self.balance += money
def TakeMoney(self,money):
if money > self.balance:
print("sorry,you balance is not satified")
else:
self.balance -= money
class InterestAcount(Bankcount):
def __init__(self,countname,countnum):
Bankcount.__init__(self,countname,countname)
self.interestrate = 0.006
self.interest = 0
def addInterest(self):
self.interest = self.balance * self.interestrate
self.balance += self.interest
mycount = InterestAcount("peng","19920402")
mycount.AddMoney(100)
mycount.TakeMoney(20)
mycount.addInterest()
print(mycount)
mycount.AddMoney(1000)
mycount.TakeMoney(200)
mycount.addInterest()
print(mycount)