#-*- coding:utf-8 -*-
#定义银行类,包含属性:用户名,账户,余额;包含方法有:查询余额,存钱,取钱
class BankAccount():
def __init__(self,name,account,balance):
self.name=name
self.account=account
self.balance=balance
def printBalance(self):
print "My balance is ",self.balance
def saveMoney(self,saving):
self.balance+=saving
def drawMoney(self,drawing):
self.balance-=drawing
#定义利率计算类,继承银行类,新增属性有银行利率,新增方法有计算本息金额
class InterestAccount(BankAccount):
def __init__(self,name,account,balance,interest):
BankAccount.__init__(self,name,account,balance)
self.interest=interest
def addInterest(self):
self.balance=self.balance*(1+interest)
print "After a year,My balance is ",self.balance
#自定义输入用户名 账户 余额 利率等信息
name=raw_input("Enter your name :")
account=raw_input("Enter your account:")
balance=float(raw_input("Enter your balance:"))
interest=float(raw_input("Enter the bank interest:"))
#创建类InterestAccount的一个对象
myAccount=InterestAccount(name,account,balance,interest)
#调用类的方法进行测试
myAccount.printBalance()
saving=float(raw_input("Enter your saving:"))
myAccount.saveMoney(saving)
myAccount.printBalance()
drawing=float(raw_input("Enter your drawing:"))
myAccount.printBalance()
myAccount.addInterest()