前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python的小程序

python的小程序

作者头像
py3study
发布2020-01-13 10:13:28
4150
发布2020-01-13 10:13:28
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
class Account:
 def __init__(self, number, name):
 self.number = number 
 self.name = name
 self.balance = 0
 def deposit(self, amount):
 if amount <= 0:
 raise ValueError('must be positive(存入金额有误)')
 self.balance += amount
 def withdraw(self, amount):
 if amount <= self.balance:
 self.balance -= amount
 else:
 raise RuntimeError('balance not enough(余额不足)')
 account=input('请输入您的账号(账号现仅能选择Justin、Momor):')
 f=int(input('请选择操作类型,1为存款,0为取款,请选择:',))
 if f==1:
 c=int(input('请输入存款金额(必须为整数):',))
 elif f==0:
 d=int(input('请输入取款金额(必须为整数):',))
 else:
 raise RuntimeError('您输入有误,谢谢使用,再见')
 if f==1:
 if c>=0:
 a=c
 else:
 raise ValueError('您输入的金额有误,谢谢使用')
 elif f==0:
 if d>=0:
 b=d
 else:
 raise ValueError('您输入的金额有误,谢谢使用') 
 acct1 = Account('123-456-789', 'Justin')
 deposit1 = acct1.deposit
 withdraw1 = acct1.withdraw
 acct2 = Account('987-654-321', 'Momor')
 deposit2 = acct2.deposit
 withdraw2 = acct2.withdraw
 if account ==acct1.name:
 if f==1:
 deposit1(a)
 elif f==0:
 withdraw1(b)
 print('账号:',acct1.name,'当前余额为:',acct1.balance) 
 elif account ==acct2.name:
 if f==1:
 deposit2(a)
 elif f==0:
 withdraw2(b)
 print('账号:',acct2.name,'当前余额为:',acct2.balance)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档