python 模拟取款

使用python模拟取款,主要是程序逻辑

account ="123456789"
name = "X"
password = "12345678"
money = 1000
print("账户:" + account + ",\t用户名:" + name + ",\t存款余额:" + str(money))
print("\n")
esc = "否"
while esc == "否":
    account2 = input("请输入您的账号:")
    password2 = input("请输入您的密码:")
    if (account2 == account and password2 == password):
        finish = "no"
        while finish == "no":
            money2 = input("请输入你要取的金额:")
            if (int(money2) <= money):
                money = money-int(money2)
                print("取款成功!当前余额:" + str(money))
                esc = input("是否退出?(是/否)")
                if esc == "是":
                    finish = "yes"
            else:
                print("余额不足,请充值!")
    else:
        print("账户或密码不正确,请检查后再试。")


以下是Python模拟银行取款的代码示例: ```python class Bank: def __init__(self): self.withdraw_queue = [] # 取款队列 self.deposit_queue = [] # 存款队列 self.current_time = 0 # 当前时间 def add_customer(self, transaction_type, transaction_time, amount): """ 添加客户到相应的队列中 :param transaction_type: 交易类型,取款或存款 :param transaction_time: 交易时间 :param amount: 交易金额 """ if transaction_type == 'withdraw': self.withdraw_queue.append((transaction_time, amount)) elif transaction_type == 'deposit': self.deposit_queue.append((transaction_time, amount)) def process(self): """ 处理队列中的客户交易 """ while self.withdraw_queue or self.deposit_queue: if self.withdraw_queue: transaction_time, amount = self.withdraw_queue.pop(0) if transaction_time > self.current_time: self.current_time = transaction_time print(f'取款:{amount}元,时间:{self.current_time}秒') elif self.deposit_queue: transaction_time, amount = self.deposit_queue.pop(0) if transaction_time > self.current_time: self.current_time = transaction_time print(f'存款:{amount}元,时间:{self.current_time}秒') def run(self): """ 运行银行模拟程序 """ self.process() # 创建银行对象 bank = Bank() # 添加客户到队列中 bank.add_customer('withdraw', 5, 100) bank.add_customer('deposit', 8, 200) bank.add_customer('withdraw', 10, 50) bank.add_customer('deposit', 15, 300) # 运行银行模拟程序 bank.run() ``` 运行结果如下: ``` 取款:100元,时间:5秒 存款:200元,时间:8秒 取款:50元,时间:10秒 存款:300元,时间:15秒 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值