编写一个程序,处理储蓄账户的取钱问题。程序的输入是目前的账户余额和需要取款的数目,输出是取款后的账户余额。如果取款数大于账户余额,请输出“Withdrawal denied.”,如果取款后的账户余额小于$150,输出信息“Balance below $150”
时间: 2024-10-23 13:12:17 浏览: 19
ATM.rar_atm 存取款机_atm 模拟程序_java atm simulation_存取款_存取款机
你可以用下面的Python代码来实现这个功能:
```python
def withdraw_funds(account_balance, withdrawal_amount):
if withdrawal_amount > account_balance:
return "Withdrawal denied."
else:
new_balance = account_balance - withdrawal_amount
if new_balance < 150:
return f"Balance below $150 after the withdrawal."
else:
return new_balance
# 示例用户输入
account_balance = float(input("请输入当前账户余额:"))
withdrawal_amount = float(input("请输入需要取款的金额:"))
result = withdraw_funds(account_balance, withdrawal_amount)
print(result)
阅读全文