编写代码1、内容:综合应用Python程序设计知识,设计与实现一款简单的手机银行系统。具体功能要求可参考以下几点: (1)登录功能,使用学号和密码登录,密码连续输错三次则账号冻结; (2)具有账户查询功能:登记账户各项信息,包括:姓名、余额,近一个月的支出和收入,账户挂失; (3)具有存款功能:可按不同货币存款,例如人民币、美元、欧元等; (4)具有取款功能:可快速取1000、2000、3000和其他金额等;(5)具有转账汇款功能:银行账号转账、手机号转账,转账记录,转账限额设置等; (6)具有投资理财功能,如基金投资、购买理财产品、购买个人养 老金; (7)期待同学们设计与实现更多其他功能: (8)系统功能完整,程序运行稳定,打包成独立的exe 文件
时间: 2024-03-14 15:49:42 浏览: 17
以下是一个较为完整的手机银行系统的 Python 代码示例,包含登录、账户查询、存款、取款、转账汇款、投资理财等多个功能:
```python
# 定义账户类
class Account:
def __init__(self, id, password, name, balance, currency):
self.id = id
self.password = password
self.name = name
self.balance = balance
self.currency = currency
self.last_month_income = 0
self.last_month_expense = 0
self.is_lost = False
# 存款
def deposit(self, amount):
self.balance += amount
print('成功存款', amount, self.currency, ',当前余额为', self.balance, self.currency, '。')
# 取款
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
print('成功取款', amount, self.currency, ',当前余额为', self.balance, self.currency, '。')
else:
print('余额不足,取款失败。')
# 转账
def transfer(self, account, amount):
if self.balance >= amount:
self.balance -= amount
account.balance += amount
print('成功向', account.name, '(', account.id, ') 转账', amount, self.currency, ',当前余额为', self.balance, self.currency, '。')
else:
print('余额不足,转账失败。')
# 定义投资产品类
class InvestmentProduct:
def __init__(self, name, price, expected_return):
self.name = name
self.price = price
self.expected_return = expected_return
# 购买
def buy(self, account):
if account.balance >= self.price:
account.balance -= self.price
print('成功购买', self.name, ',当前余额为', account.balance, account.currency, '。')
else:
print('余额不足,购买失败。')
# 预计收益
def get_expected_return(self):
return self.price * self.expected_return
# 定义银行类
class Bank:
def __init__(self):
self.accounts = []
self.login_id = None
self.login_password = None
self.login_attempts = 0
# 注册账户
def register(self, id, password, name, balance, currency):
self.accounts.append(Account(id, password, name, balance, currency))
print('成功注册账户', id, ',当前账户数量为', len(self.accounts), '。')
# 登录
def login(self, id, password):
for account in self.accounts:
if account.id == id:
if account.password == password:
if account.is_lost:
print('账户已挂失,无法登录。')
return
self.login_id = id
self.login_password = password
self.login_attempts = 0
print('成功登录账户', id, '。')
return
else:
self.login_attempts += 1
if self.login_attempts >= 3:
print('密码错误次数超过3次,账户已被冻结。')
account.is_lost = True
return
else:
print('密码错误,还有', 3 - self.login_attempts, '次机会。')
return
print('账户不存在。')
# 账户查询
def check_balance(self):
for account in self.accounts:
if account.id == self.login_id:
print('账户信息如下:')
print('姓名:', account.name)
print('余额:', account.balance, account.currency)
print('上个月收入:', account.last_month_income, account.currency)
print('上个月支出:', account.last_month_expense, account.currency)
print('账户状态:', '挂失' if account.is_lost else '正常')
return
print('未登录或账户不存在。')
# 存款
def deposit(self, amount, currency):
for account in self.accounts:
if account.id == self.login_id and account.currency == currency:
account.deposit(amount)
return
print('未登录或账户不存在或货币类型不正确。')
# 取款
def withdraw(self, amount):
for account in self.accounts:
if account.id == self.login_id:
account.withdraw(amount)
return
print('未登录或账户不存在。')
# 转账
def transfer(self, to_id, amount):
for account in self.accounts:
if account.id == self.login_id:
for to_account in self.accounts:
if to_account.id == to_id:
account.transfer(to_account, amount)
return
print('目标账户不存在。')
return
print('未登录或账户不存在。')
# 购买投资产品
def buy_investment_product(self, product_name):
for account in self.accounts:
if account.id == self.login_id:
for product in investment_products:
if product.name == product_name:
product.buy(account)
return
print('投资产品不存在。')
return
print('未登录或账户不存在。')
# 查询投资产品预计收益
def check_investment_product_return(self, product_name):
for product in investment_products:
if product.name == product_name:
print('预计收益为', product.get_expected_return(), product.currency, '。')
return
print('投资产品不存在。')
# 定义投资产品列表
investment_products = [
InvestmentProduct('基金A', 1000, 0.05),
InvestmentProduct('基金B', 2000, 0.08),
InvestmentProduct('理财产品A', 5000, 0.1),
InvestmentProduct('个人养老金A', 10000, 0.15)
]
# 测试代码
bank = Bank()
bank.register('123456', '123456', '张三', 1000, '人民币')
bank.login('123456', '654321') # 密码错误
bank.login('123456', '123456') # 成功登录
bank.check_balance() # 显示账户信息
bank.deposit(1000, '人民币') # 存入1000元人民币
bank.deposit(100, '美元') # 存入100美元,货币类型不正确
bank.withdraw(500) # 取出500元人民币
bank.transfer('654321', 300) # 转账300元人民币给账户654321
bank.transfer('654321', 8000) # 余额不足,转账失败
bank.buy_investment_product('基金A') # 购买基金A
bank.check_investment_product_return('基金A') # 查询基金A预计收益
bank.check_investment_product_return('基金C') # 投资产品不存在
bank.check_balance() # 显示账户信息
```
以上代码示例只是一个简单的模拟,具体的实现可能还需要根据实际情况进行调整和扩展。同时,如果需要将程序打包成独立的 exe 文件,可以使用 PyInstaller 等工具实现。