用Python便编写ATMh
时间: 2023-05-14 12:05:57 浏览: 36
非常感谢您的提问。以下是一个简单的 Python ATM 程序的示例代码:
```python
balance = 1000
def withdraw(amount):
global balance
if amount > balance:
print("余额不足!")
else:
balance -= amount
print("取款成功!")
def deposit(amount):
global balance
balance += amount
print("存款成功!")
def check_balance():
global balance
print("您的余额为:", balance)
while True:
print("请选择操作:")
print("1. 取款")
print("2. 存款")
print("3. 查询余额")
print("4. 退出")
choice = input()
if choice == "1":
amount = int(input("请输入取款金额:"))
withdraw(amount)
elif choice == "2":
amount = int(input("请输入存款金额:"))
deposit(amount)
elif choice == "3":
check_balance()
elif choice == "4":
print("感谢使用!")
break
else:
print("无效的选择,请重新输入!")
```
希望这个示例代码能够帮助您编写自己的 Python ATM 程序。如果您有任何问题,请随时问我。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)