def withdrawal(): while True: balance = input("请输入金额:") if balance == "q": break elif balance.isdigit(): a = int(user_list[account]["余额"]) user_list[account]["余额"] = a - int(balance) print("取款成功") print("余额:" + str(user_list[account]["余额"])) break else: print("输入有误,请重新输入")
时间: 2023-02-06 09:18:08 浏览: 157
这是一个 Python 函数,用于实现取款的功能。
函数的流程如下:
1. 使用 `while` 循环,不断询问用户输入金额。
2. 如果用户输入 `q`,则退出循环。
3. 如果用户输入的是数字,则将账户余额减去输入的金额,并输出 "取款成功" 和当前的余额。然后退出循环。
4. 否则,输出 "输入有误,请重新输入",继续循环。
相关问题
补全Account和FreeChecking类的实现 class Account: """An account has a balance and a holder. >>> a = Account('John') >>> a.deposit(12) 12 >>> a.balance 12 >>> a.interest 0.02 >>> a.time_to_retire(20) 26 >>> a.balance # balance 保持不变 12 >>> a.withdraw(11) # 每次取款额度不超过10,超过无法取出 "Can't withdraw that amount" >>> a.withdraw(10) 2 >>> a.withdraw(10) 'Insufficient funds' """ def __init__(self, account_holder): def deposit(self, amount): def withdraw(self, amount): def time_to_retire(self, amount): """Return the number of years until balance would grow to amount.""" assert self.balance > 0 and amount > 0 and self.interest > 0 class FreeChecking(Account): """A bank account that charges for withdrawals, but the first two are free! >>> ch = FreeChecking('Jack') >>> ch.balance = 20 >>> ch.withdraw(100) # 首次取款免费,不论是否成功,免费次数减少1次 'Insufficient funds' >>> ch.withdraw(3) # 第二次取款免费 17 >>> ch.balance 17 >>> ch.withdraw(3) # 2次免费用完,开始收费 13 >>> ch.withdraw(3) 9 >>> ch2 = FreeChecking('John') >>> ch2.balance = 10 >>> ch2.withdraw(3) # 首次免费 7 >>> ch.withdraw(3) # 2次免费 5 >>> ch.withdraw(5) # 余额不足 'Insufficient funds' """ def __init__(self, account_holder): def withdraw(self, amount): import doctest doctest.testmod()
class Account:
"""An account has a balance and a holder.
>>> a = Account('John')
>>> a.deposit(12)
12
>>> a.balance
12
>>> a.interest
0.02
>>> a.time_to_retire(20)
26
>>> a.balance # balance 保持不变
12
>>> a.withdraw(11) # 每次取款额度不超过10,超过无法取出
"Can't withdraw that amount"
>>> a.withdraw(10)
2
>>> a.withdraw(10)
'Insufficient funds'
"""
def __init__(self, account_holder):
self.holder = account_holder
self.balance = 0
self.interest = 0.02
def deposit(self, amount):
self.balance += amount
return self.balance
def withdraw(self, amount):
if amount > 10:
return "Can't withdraw that amount"
elif self.balance < amount:
return 'Insufficient funds'
else:
self.balance -= amount
return self.balance
def time_to_retire(self, amount):
assert self.balance > 0 and amount > 0 and self.interest > 0
years = 0
while self.balance < amount:
self.balance *= (1 + self.interest)
years += 1
return years
class FreeChecking(Account):
"""A bank account that charges for withdrawals, but the first two are free!
>>> ch = FreeChecking('Jack')
>>> ch.balance = 20
>>> ch.withdraw(100) # 首次取款免费,不论是否成功,免费次数减少1次
'Insufficient funds'
>>> ch.withdraw(3) # 第二次取款免费
17
>>> ch.balance
17
>>> ch.withdraw(3) # 2次免费用完,开始收费
13
>>> ch.withdraw(3)
9
>>> ch2 = FreeChecking('John')
>>> ch2.balance = 10
>>> ch2.withdraw(3) # 首次免费
7
>>> ch.withdraw(3) # 2次免费
5
>>> ch.withdraw(5) # 余额不足
'Insufficient funds'
"""
def __init__(self, account_holder):
super().__init__(account_holder)
self.free_withdrawals = 2
self.withdrawal_fee = 1
def withdraw(self, amount):
if self.free_withdrawals > 0:
self.free_withdrawals -= 1
return super().withdraw(amount)
else:
return super().withdraw(amount + self.withdrawal_fee)
import doctest
doctest.testmod()
statusCode:400 failed,resp code = 400,return body = {"code":"INVALID_REQUEST","message":"产品权限异常"} 17:10:18.561 [http-nio-8080-exec-1] ERROR c.m.f.w.e.GlobalExceptionHandler - [handleException,81] - 请求地址'/front/withdrawal',发生系统异常.
看起来这是一个请求地址 '/front/withdrawal' 在请求时发生了一个系统异常,返回的状态码为400,意味着请求出现了错误,可能是由于请求参数不正确或者权限不足导致的。具体的错误信息是:"INVALID_REQUEST",意思是无效请求,"产品权限异常",意思是产品权限出现异常。需要检查请求参数是否正确,以及是否具有相应的权限。
阅读全文