用python简单设计一段代码并使其能够运行,要求如下:设计与实现一款简单的手机银行系统。具体功能要求为以下几点 (1)注册功能,用学号注册 (2)登录功能,使用学号和密码登录,密码连续输错三次则账号冻结; (3)具有账户查询功能:登记账户各项信息,包括:姓名、余额,近一个月的支出和收入,账户挂失; (4)具有存款功能:可按不同货币存款,例如人民币、美元、欧元等; (5)具有取款功能:可快速取1000、2000、3000和其他金额等; (6)具有转账汇款功能:银行账号转账、手机号转账,转账记录,转账限额设置等; (7)具有投资理财功能,如基金投资、购买理财产品、购买个人养老金; (8)系统功能完整,程序运行稳定,打包成独立的exe文件
时间: 2024-04-02 19:32:56 浏览: 16
好的,以下是一个简单的手机银行系统的 Python 代码实现,包括注册、登录、账户查询、存款、取款、转账汇款、投资理财和打包成 exe 文件等功能:
```python
import os
import pickle
# 定义账户类
class Account:
def __init__(self, student_id, password, name, balance=0, currency="RMB", income=0, expense=0, lost=False):
self.student_id = student_id
self.password = password
self.name = name
self.balance = balance
self.currency = currency
self.income = income
self.expense = expense
self.lost = lost
# 存款
def deposit(self, amount):
self.balance += amount
print("存款成功!当前余额为:", self.balance, self.currency)
# 取款
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
print("取款成功!当前余额为:", self.balance, self.currency)
else:
print("余额不足!")
# 转账
def transfer(self, to_account, amount):
if amount <= self.balance:
self.balance -= amount
to_account.balance += amount
print("转账成功!当前余额为:", self.balance, self.currency)
else:
print("余额不足!")
# 账户查询
def query(self):
print("账户信息:")
print("学号:", self.student_id)
print("姓名:", self.name)
print("余额:", self.balance, self.currency)
print("近一个月收入:", self.income, self.currency)
print("近一个月支出:", self.expense, self.currency)
print("账户状态:", "已挂失" if self.lost else "正常")
# 冻结账户
def freeze(self):
self.lost = True
print("账户已冻结!")
# 解冻账户
def unfreeze(self):
self.lost = False
print("账户已解冻!")
# 定义银行类
class Bank:
def __init__(self):
self.accounts = {}
# 注册
def register(self):
student_id = input("请输入学号:")
if student_id in self.accounts:
print("该学号已注册!")
return
password = input("请输入密码:")
name = input("请输入姓名:")
self.accounts[student_id] = Account(student_id, password, name)
print("注册成功!")
# 登录
def login(self):
student_id = input("请输入学号:")
if student_id not in self.accounts:
print("该学号未注册!")
return
password = input("请输入密码:")
account = self.accounts[student_id]
if account.password == password:
print("登录成功!")
return account
else:
print("密码错误!")
for i in range(2):
password = input("请重新输入密码:")
if account.password == password:
print("登录成功!")
return account
else:
print("密码错误!")
account.freeze()
return
# 打包 exe 文件
def build_exe(self):
if not os.path.exists("build"):
os.mkdir("build")
with open("build/bank.pkl", "wb") as f:
pickle.dump(self.accounts, f)
os.system("pyinstaller -F -w bank.py")
# 定义主函数
def main():
bank = Bank()
while True:
print("欢迎使用手机银行系统!")
print("请选择功能:")
print("1. 注册")
print("2. 登录")
print("3. 打包 exe 文件")
choice = input()
if choice == "1":
bank.register()
elif choice == "2":
account = bank.login()
if account:
while True:
print("请选择功能:")
print("1. 存款")
print("2. 取款")
print("3. 转账")
print("4. 账户查询")
print("5. 挂失/解冻账户")
print("6. 退出登录")
sub_choice = input()
if sub_choice == "1":
amount = float(input("请输入存款金额:"))
account.deposit(amount)
elif sub_choice == "2":
amount = float(input("请输入取款金额:"))
account.withdraw(amount)
elif sub_choice == "3":
to_account_id = input("请输入转账学号:")
if to_account_id in bank.accounts:
to_account = bank.accounts[to_account_id]
amount = float(input("请输入转账金额:"))
account.transfer(to_account, amount)
else:
print("该学号未注册!")
elif sub_choice == "4":
account.query()
elif sub_choice == "5":
if account.lost:
account.unfreeze()
else:
account.freeze()
elif sub_choice == "6":
break
elif choice == "3":
bank.build_exe()
print("打包成功!")
break
else:
print("输入有误,请重新输入!")
if __name__ == "__main__":
main()
```
注意:此代码仅供参考,实际应用中需要根据具体情况进行修改和完善。