• 【Python】python-一个class继承的小case


    #-*- 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()
  • 相关阅读:
    flutter添加启动图及设置启动时间
    flutter中通过循环渲染组件
    flutter学习资料汇总
    flutter中显现登录页面成功后跳转的方法
    flutter 常用视图组件
    mpvue学习笔记
    按钮放大动画效果
    一位练习时长两年半的内网渗透练习生
    Kali系统中20个超好用黑客渗透工具,你知道几个?
    渗透测试之三内网跳板
  • 原文地址:https://www.cnblogs.com/zhaoxd07/p/4918433.html
Copyright © 2020-2023  润新知