内容:综合应用Python程序设计知识,设计与实现一款简单的手机银行系统。 具体功能要求可参考以下几点: (1)登录功能,使用学号和密码登录,密码连续输错三次则账号冻结; (2)具有账户查询功能:登记账户各项信息,包括:姓名、余额,近一个月的支出和收入,账户挂失; (3)具有存款功能:可按不同货币存款,例如人民币、美元、欧元等; (4)具有取款功能:可快速取1000、2000、3000和其他金额等; (5)具有转账汇款功能:银行账号转账、手机号转账,转账记录,转账限额设置等; (6)具有投资理财功能,如基金投资、购买理财产品、购买个人养老金; (7)期待同学们设计与实现更多其他功能; (8)系统功能完整,程序运行稳定,打包成独立的exe文件
时间: 2024-04-03 15:33:00 浏览: 13
好的,这是一个比较复杂的系统,需要用到多个模块和库。以下是一个基本的框架,你可以根据需要进行修改和扩展:
```python
import os
import json
import random
# 定义全局变量
accounts = {} # 存储账户信息
current_user = None # 当前登录用户
currencies = ["CNY", "USD", "EUR"] # 可用货币种类
exchange_rates = { # 货币汇率表
"CNY": {"CNY": 1.0, "USD": 0.16, "EUR": 0.14},
"USD": {"CNY": 6.41, "USD": 1.0, "EUR": 0.86},
"EUR": {"CNY": 7.14, "USD": 1.16, "EUR": 1.0}
}
# 加载账户信息
def load_accounts():
global accounts
if os.path.isfile("accounts.json"):
with open("accounts.json", "r") as f:
accounts = json.load(f)
# 保存账户信息
def save_accounts():
global accounts
with open("accounts.json", "w") as f:
json.dump(accounts, f)
# 注册账户
def register():
global accounts
while True:
student_id = input("请输入学号:")
if student_id in accounts:
print("该学号已被注册,请重新输入。")
else:
break
name = input("请输入姓名:")
password = input("请输入密码:")
account = {
"name": name,
"password": password,
"balance": {"CNY": 0, "USD": 0, "EUR": 0},
"transactions": []
}
accounts[student_id] = account
save_accounts()
print("注册成功!")
# 账户登录
def login():
global accounts, current_user
student_id = input("请输入学号:")
if student_id not in accounts:
print("该学号未注册,请重新输入。")
return
password = input("请输入密码:")
account = accounts[student_id]
if password != account["password"]:
if "login_attempts" not in account:
account["login_attempts"] = 1
else:
account["login_attempts"] += 1
if account["login_attempts"] >= 3:
account["is_locked"] = True
print("密码错误次数超过3次,账号已被冻结。")
else:
print("密码错误,请重新输入。")
save_accounts()
return
if "is_locked" in account and account["is_locked"]:
print("该账号已被冻结,请联系管理员。")
return
current_user = student_id
print("登录成功!")
# 账户查询
def query():
global accounts, current_user
if not current_user:
print("请先登录。")
return
account = accounts[current_user]
print("姓名:", account["name"])
print("余额:")
for currency, balance in account["balance"].items():
print(currency, ":", balance)
print("近一个月支出:")
# TODO: 显示近一个月的支出
print("近一个月收入:")
# TODO: 显示近一个月的收入
if "is_lost" in account and account["is_lost"]:
print("该账户已挂失。")
# 存款
def deposit():
global accounts, current_user, currencies
if not current_user:
print("请先登录。")
return
account = accounts[current_user]
print("请选择货币种类:")
for i, currency in enumerate(currencies):
print(i+1, currency)
choice = input("请输入编号:")
if not choice.isdigit() or int(choice) < 1 or int(choice) > len(currencies):
print("无效的选择。")
return
currency = currencies[int(choice)-1]
amount = input("请输入存款金额:")
if not amount.isdigit():
print("无效的金额。")
return
amount = int(amount)
exchange_rate = exchange_rates["CNY"][currency]
cny_amount = amount / exchange_rate
account["balance"][currency] += amount
account["balance"]["CNY"] += cny_amount
account["transactions"].append({
"type": "deposit",
"currency": currency,
"amount": amount,
"exchange_rate": exchange_rate
})
save_accounts()
print("存款成功!")
# 取款
def withdraw():
global accounts, current_user
if not current_user:
print("请先登录。")
return
account = accounts[current_user]
print("请选择取款金额:")
print("1. 1000")
print("2. 2000")
print("3. 3000")
print("4. 其他")
choice = input("请输入编号:")
if not choice.isdigit() or int(choice) < 1 or int(choice) > 4:
print("无效的选择。")
return
if int(choice) == 4:
amount = input("请输入取款金额:")
if not amount.isdigit():
print("无效的金额。")
return
amount = int(amount)
else:
amount = int(choice) * 1000
if account["balance"]["CNY"] < amount:
print("余额不足。")
return
account["balance"]["CNY"] -= amount
account["transactions"].append({
"type": "withdraw",
"currency": "CNY",
"amount": amount
})
save_accounts()
print("取款成功!")
# 转账汇款
def transfer():
global accounts, current_user
if not current_user:
print("请先登录。")
return
account = accounts[current_user]
print("请选择转账方式:")
print("1. 银行账号转账")
print("2. 手机号转账")
choice = input("请输入编号:")
if not choice.isdigit() or int(choice) < 1 or int(choice) > 2:
print("无效的选择。")
return
if int(choice) == 1:
# 银行账号转账
# TODO
pass
else:
# 手机号转账
# TODO
pass
# 投资理财
def invest():
global accounts, current_user
if not current_user:
print("请先登录。")
return
account = accounts[current_user]
print("请选择投资方式:")
print("1. 基金投资")
print("2. 购买理财产品")
print("3. 购买个人养老金")
choice = input("请输入编号:")
if not choice.isdigit() or int(choice) < 1 or int(choice) > 3:
print("无效的选择。")
return
if int(choice) == 1:
# 基金投资
# TODO
pass
elif int(choice) == 2:
# 购买理财产品
# TODO
pass
else:
# 购买个人养老金
# TODO
pass
# 主菜单
def main_menu():
print("欢迎使用手机银行系统!")
while True:
print("请选择操作:")
print("1. 注册账户")
print("2. 登录")
print("3. 账户查询")
print("4. 存款")
print("5. 取款")
print("6. 转账汇款")
print("7. 投资理财")
print("8. 退出")
choice = input("请输入编号:")
if not choice.isdigit() or int(choice) < 1 or int(choice) > 8:
print("无效的选择。")
continue
if int(choice) == 1:
register()
elif int(choice) == 2:
login()
elif int(choice) == 3:
query()
elif int(choice) == 4:
deposit()
elif int(choice) == 5:
withdraw()
elif int(choice) == 6:
transfer()
elif int(choice) == 7:
invest()
else:
print("谢谢使用!")
break
# 程序入口
if __name__ == "__main__":
load_accounts()
main_menu()
```
以上代码实现了一个基本的手机银行系统,包括注册账户、登录、账户查询、存款、取款、转账汇款、投资理财等功能。注意,由于实现这些功能需要大量的代码和算法,因此以上代码只是一个框架,需要你自己完成其中的 TODO 部分,即具体的实现代码。同时,还需要你根据需求进行修改和扩展,例如添加更多的交易类型、货币种类、投资方式等等。
最后,你可以使用 PyInstaller 等工具将代码打包成 exe 文件,这样用户可以直接运行程序,而不需要安装 Python 环境。