ATM模拟程序能够完成ATM的主要功能,包括: ①显示欢迎词及提示信息;②用户插卡,ATM验证用户账号及密码有效性,输入错误3次即被锁卡;程序所涉及到的用户资料、银行帐户、存取款记录等信息保存在数据文件中
时间: 2024-06-14 17:05:27 浏览: 11
ATM模拟程序可以完成以下主要功能:
1. 显示欢迎词及提示信息。
2. 用户插卡,ATM验证用户账号及密码有效性,输入错误3次即被锁卡。
3. 添加新用户信息并初始化,确保不重复添加。
4. 注销账号,对用户进行临时冻结。
5. 激活账号,对冻结的账号解封。
6. 查看所有用户信息或指定用户信息。
7. 查看指定时间段业务交易情况,包括取款、存款和全部交易。
8. 退出程序,将用户信息写入数据文件。
以下是一个简单的ATM模拟程序的示例代码:
```python
class User:
def __init__(self, account, password):
self.account = account
self.password = password
self.is_locked = False
class ATM:
def __init__(self):
self.users = []
self.current_user = None
def welcome(self):
print("欢迎使用ATM机!")
def login(self):
account = input("请输入账号:")
password = input("请输入密码:")
for user in self.users:
if user.account == account and user.password == password:
if user.is_locked:
print("账号已被锁定,请联系客服解锁。")
return
self.current_user = user
print("登录成功!")
return
print("账号或密码错误,请重新输入。")
def add_user(self, account, password):
for user in self.users:
if user.account == account:
print("账号已存在,请重新输入。")
return
new_user = User(account, password)
self.users.append(new_user)
print("用户添加成功!")
def logout(self):
self.current_user = None
print("退出成功!")
def display_menu(self):
print("1. 添加新用户")
print("2. 注销账号")
print("3. 激活账号")
print("4. 查看所有用户信息")
print("5. 查看指定用户信息")
print("6. 查看指定时间段业务交易情况")
print("7. 退出")
def run(self):
self.welcome()
while True:
self.display_menu()
choice = input("请输入选项:")
if choice == "1":
account = input("请输入账号:")
password = input("请输入密码:")
self.add_user(account, password)
elif choice == "2":
# 注销账号逻辑
pass
elif choice == "3":
# 激活账号逻辑
pass
elif choice == "4":
# 查看所有用户信息逻辑
pass
elif choice == "5":
# 查看指定用户信息逻辑
pass
elif choice == "6":
# 查看指定时间段业务交易情况逻辑
pass
elif choice == "7":
self.logout()
break
else:
print("无效选项,请重新输入。")
atm = ATM()
atm.run()
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)