与小卡特一起学python 第14章 对象 动手试一试-程序员宅基地

技术标签: python  

#14章对象动手试一试
#14.1对应银行账户的类如下所示:
class BankAccout:
    def __init__(self,acct_number,acct_name):
        self.acct_number = acct_number
        self.acct_name = acct_name
        self.balance = 0.0
    def displayBalance(self):
        print("The account balance is:",self.balance)

    def deposit(self,amount):
        self.balance = self.balance + amount
        print("You deposited",amount)
        print("The new balance is:",self.balance)
    def withdraw(self,amount):
        if self.balance >=amount:
            self.balance = self.balance - amount
            print ("You withdrew",amount)
            print ("The new balance is :",self.balance)
        else:
            print("You tried to withdraw",amount)
            print("The account balance is:",self.balance)
            print("Withdrawal denied. Not enough funds.")
myAccount = BankAccout(234567,"Warren Sande")
print("Account name:",myAccount.acct_name)
print("Account number:",myAccount.acct_number)
myAccount.displayBalance()

myAccount.deposit(34.52)
myAccount.withdraw(12.25)
myAccount.withdraw(30.8)

#14.2建立一个账户信息,计算利息
##class InterestAccount(BankAccount):
##    def __init__(self,acct_number,acct_name,rate):
##        BankAccount.__init__(self,acct_number,acct_name)
##        self.rate = rate
##    def addInterest (self):
##        interest = self.balance * self.rate
##        print("adding interest to the account,",self.rate * 100,"percent")
##        self.deposit (interest)

class BankAccount:
    def __init__(self, acct_number, acct_name):
        self.acct_number = acct_number
        self.acct_name = acct_name
        self.balance = 0.0

    def displayBalance(self):
        print( "The account balance is:", self.balance)

    def deposit(self, amount):
        self.balance = self.balance + amount
        print( "You deposited", amount)
        print( "The new balance is:", self.balance)
        
    def withdraw(self, amount):
        if self.balance >= amount:
            self.balance = self.balance - amount
            print( "You withdrew", amount)
            print( "The new balance is:", self.balance)
        else:
            print ("You tried to withdraw", amount)
            print ("The account balance is:", self.balance)
            print("Withdrawl denied.  Not enough funds.")

class InterestAccount(BankAccount):
    def addInterest(self, rate):
        interest = self.balance * rate
        print( "adding interest to the account,",rate * 100,"percent")
        self.deposit (interest)
myAccount = InterestAccount(234567, "Warren Sande")
print ("Account name:", myAccount.acct_name)
print( "Account number:", myAccount.acct_number)
myAccount.displayBalance()
myAccount.deposit(34.52)
myAccount.addInterest(0.11)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/220205/viewspace-2076519/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/220205/viewspace-2076519/

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/cuihui3254/article/details/100334651

智能推荐

unet知乎_[论文笔记]DCAN for Multi-task Brain Tumor Segmentation-程序员宅基地

文章浏览阅读423次。0 写在前面本篇论文《Deep Cascaded Attention Network for Multi-task Brain Tumor Segmentation》是中科大和其他高校合作的一篇结合attention机制的文章,文章发表在2020MICCAI.Github地址: 未给出数据集:BraTS challenge 2018解决问题:用cascaded model解决muti-task的问..._brain network 知乎

canal-admin的高可用使用,单机使用,HA使用,阿里的canal的UI界面,管理canal的实例,以及问题_canal ui-程序员宅基地

文章浏览阅读9.8k次。一、软件下载1、介绍canal的主要的作用就是通过MySQL的binlog日志文件,同步数据到MQ,MQ包含mysql、kafka、tcp等等 canal-admin是一个webUI界面,通过界面配置的方式,管理canal的配置文件,方便易于管理。2、下载使用的有点击下载:canal.deployer-1.1.4.tar.gz 和 canal.admin-1.1.4.tar...._canal ui

升级samba-程序员宅基地

文章浏览阅读5.4k次。最近smaba因为安全问题需要升级.需要下载代码和安全补丁,重新编译安装。下面是步骤。1.下载代码。我选择的版本是 4.7.5. https://download.samba.org/pub/samba/stable/samba-4.7.5.tar.gz下载补丁:https://www.samba.org/samba/ftp/patches/security/samba-4.7.5-securit..._升级samba

Java 变量一定要初始化吗?_java所有变量在使用前都必须进行初始化-程序员宅基地

文章浏览阅读6.2k次,点赞18次,收藏35次。Java 变量一定要初始化吗?解答。。。_java所有变量在使用前都必须进行初始化

TensorFlow-gpu安装心得,一小时搞定了_tensorflow-gpu要安装多久-程序员宅基地

文章浏览阅读655次。搞了三天的TensorFlow-gpu的安装,终于好了,我稍微总结一下。前两天一直在我的台式机上安装,失败了好多次,今天晚上我只用了一个小时就把我的xps上也装上了TensorFlow-gpu。回顾一下安装步骤吧,希望以后换电脑了也不会忘记。首先,我的台式机配置是显卡GTX 1070,笔记本是GTX970M的,所以安装python3.6+TensorFlow-gpu1.8+cuda9.0+cud..._tensorflow-gpu要安装多久

java/jsp/ssm医药管理系统设计与实现【2024年毕设】-程序员宅基地

文章浏览阅读42次。springboot基于Android的自助游线路规划系统。springboot基于SpringBoot的医院就医平台。springboot基于微信小程序的出入校园登记管理系统。springboot基于Java的网上花店。springboot健身俱乐部会籍管理系统。springboot大学英语四六级管理系统。springboot校园二手物品交易平台。springboot心理咨询预约导诊系统。springboot小区疫情事件处理系统。springboot冬奥会志愿者服务系统。

随便推点

linux文件系统(目录)层次_目录层级表示-程序员宅基地

文章浏览阅读1.6w次,点赞3次,收藏9次。虽然 Linux 系统的发行版众多,但他们的目录配置却看起来都差不多,那是因为,大多数 Linux 发行版都遵循了文件系统层次结构标准(Filesystem Hierarchy Standard,FHS),FHS 定义了系统中每个区域的用途、所需要的最小构成的文件和目录,同时还给出了例外处理与矛盾处理。_目录层级表示

SSH------------Hessian 第一个程序_hessian ssh-程序员宅基地

文章浏览阅读107次。步骤: 第一步 创建一个web项目,取名HessianServer导入hessian-4.0.33.jar 第二步 创建一个Service接口和实现 Customer必须实现Serializable接口 public class CustomerServiceImpl implements ICustomerService{ @Override public List<Customer> findAll(..._hessian ssh

CPU的工作原理通俗理解_cpu工作图-程序员宅基地

文章浏览阅读1.2k次。1、CPU工作理解简单介绍 CPU 的工作原理_有趣的人生 一半是山川湖海 一半是初心情怀 -程序员宅基地CPU的内部架构和工作原理-wjlkoorey258-ChinaUnix博客2、CPU指令集通俗的说一说指令集是什么?CPU是如何工作的?_qq_40585684的博客-程序员宅基地3、认识CPU的工作原理认识CPU的工作原理_延瓒-程序员宅基地_cpu的工作原理是什么4、CPU GPU通俗易懂的告诉你CPU和GPU的区别_苝花向暖丨楠枝向寒-程序员宅基地_cpu和gpu_cpu工作图

c语言学生综合测评系统_c语言图书管理系统_c语言学生综合测评系统_c语言个人账本管理系统...-程序员宅基地

文章浏览阅读688次。c语言销售管理系统设计c语言设计管理系统,c图书管理系统设计,学生管理系统c语言,职工管理系统c语言,c语言图书管理系统,c语言成绩管理系统,c语言管理系统,c语言银行管理系统,c语言工资管理系统,c语言超市管理系统利用C语言编程技术,编写销售管理系统,其中包括详尽的函数描述,数据类型的描述,主要... 设计(论文)题目:销售管理系统设计一、题目内容描述:某公司有四个销售员(编号:1-4),负C语..._销售管理系统的设计。某公司有四个销售员(编号:1-4),负责销售五种产品(编号:1

Python可视化matplotlib&seborn16-相关性热图(correlation heatmap& correlation clustermap)_相关性热图英语-程序员宅基地

文章浏览阅读2.9k次,点赞5次,收藏21次。介绍python绘制相关性热图(correlation heatmap& correlation clustermap)_相关性热图英语

来自实践中的教训,有时候纯ffmpeg命令并不好使,还得需要ffmpy包装器_ffmpeg stdout-程序员宅基地

文章浏览阅读2.6k次,点赞2次,收藏2次。ffmpy包装器了解下_ffmpeg stdout

推荐文章

热门文章

相关标签