class Account:
# 初始化方法,创建账户
def __init__(self, name, password, money=0):
self.name = name
self.password = password
self.money = money
# 存款
def deposit(self, password, money):
if password == self.password:
if isinstance(money, (int, float)) and money >= 0: # 判断money属于int或者float类型
self.money += money
return '成功存款:%s元,账户余额为:%s元' % (money, self.money)
else:
return '请输入正确的存款金额'
else:
return '请输入正确的账户密码'
# 取款
def withdraw(self, password, money):
if password == self.password:
if isinstance(money, (int, float)) and 0 <= money <= self.money: # 判断money属于int或者float类型
self.money += money
return '成功取款:%s元,账户余额为:%s元' % (money, self.money)
else:
return '请输入正确的取款金额'
else:
return '请输入正确的账户密码'
# 查询余额
def query(self, password):
if password == self.password:
return '您的账户余额为:%s元' % self.money
else:
return '请输入正确的账户密码'
# 销户
def close(self, password):
if password == self.password:
if self.money == 0:
self.name = ""
self.password = ''
self.money = 0
else:
return '您的账户余额不为0,请取完金额再来执行注销操作'
else:
return '请输入正确的密码'
# 创建一个用户对象,实例化
user = Account('user', password=123)
Python实现银行存款系统
最新推荐文章于 2024-09-03 12:55:37 发布