Python父与子的编程之旅 第十四章答案

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)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值