用python简单设计一段代码,要求如下:设计与实现一款简单的手机银行系统。具体功能要求为以下几点: (1)登录功能,使用学号和密码登录,密码连续输错三次则账号冻结; (2)具有账户查询功能:登记账户各项信息,包括:姓名、余额,近一个月的支出和收入,账户挂失; (3)具有存款功能:可按不同货币存款,例如人民币、美元、欧元等; (4)具有取款功能:可快速取1000、2000、3000和其他金额等; (5)具有转账汇款功能:银行账号转账、手机号转账,转账记录,转账限额设置等; (6)具有投资理财功能,如基金投资、购买理财产品、购买个人养老金; (7)可以利用自定义学号注册账号; (8)系统功能完整,程序运行稳定,打包成独立的exe文件
时间: 2024-04-02 16:33:14 浏览: 76
python 银行管理系统 实验报告及源码
5星 · 资源好评率100%
以下是一种简单的手机银行系统代码实现,具体要求已在注释中说明:
```python
import getpass
# 定义账户类
class Account:
def __init__(self, name, balance, income, expense, is_lost):
self.name = name
self.balance = balance
self.income = income
self.expense = expense
self.is_lost = is_lost
# 存款
def deposit(self, amount):
self.balance += amount
print('存款成功!')
# 取款
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
print('取款成功!')
else:
print('余额不足!')
# 转账
def transfer(self, other, amount):
if amount <= self.balance:
self.balance -= amount
other.balance += amount
print('转账成功!')
else:
print('余额不足!')
# 定义银行类
class Bank:
def __init__(self):
self.accounts = {}
self.login_attempts = {}
# 注册账户
def register(self, id, name, balance, income, expense, is_lost):
self.accounts[id] = Account(name, balance, income, expense, is_lost)
# 登录
def login(self, id, password):
if id in self.login_attempts and self.login_attempts[id] >= 3:
print('账号已冻结!')
return False
if id in self.accounts and password == id:
self.login_attempts[id] = 0
print('登录成功!')
return True
else:
if id in self.login_attempts:
self.login_attempts[id] += 1
else:
self.login_attempts[id] = 1
print('用户名或密码错误!')
return False
# 查询账户信息
def query_account(self, id):
if id in self.accounts:
account = self.accounts[id]
print('姓名:', account.name)
print('余额:', account.balance)
print('收入:', account.income)
print('支出:', account.expense)
print('是否挂失:', account.is_lost)
else:
print('账号不存在!')
# 存款
def deposit(self, id, amount):
if id in self.accounts:
account = self.accounts[id]
account.deposit(amount)
else:
print('账号不存在!')
# 取款
def withdraw(self, id, amount):
if id in self.accounts:
account = self.accounts[id]
account.withdraw(amount)
else:
print('账号不存在!')
# 转账
def transfer(self, id, other_id, amount):
if id in self.accounts and other_id in self.accounts:
account = self.accounts[id]
other_account = self.accounts[other_id]
account.transfer(other_account, amount)
else:
print('账号不存在!')
# 创建银行对象
bank = Bank()
# 注册账户
bank.register('001', '张三', 10000, 5000, 3000, False)
bank.register('002', '李四', 20000, 8000, 4000, False)
# 登录
id = input('请输入学号:')
password = getpass.getpass('请输入密码:') # 隐藏密码输入
bank.login(id, password)
# 查询账户信息
bank.query_account(id)
# 存款
amount = float(input('请输入存款金额:'))
bank.deposit(id, amount)
# 取款
amount = float(input('请输入取款金额:'))
bank.withdraw(id, amount)
# 转账
other_id = input('请输入转账账号:')
amount = float(input('请输入转账金额:'))
bank.transfer(id, other_id, amount)
```
注意:以上代码只是一个简单的实现,还有很多功能需要完善和优化。同时,打包成独立的exe文件需要使用第三方库,如pyinstaller等。
阅读全文