编写一个银行账户管理系统程序。银行客户信息以一个账户一条记录的形式存储,每个账户记录包含的信息有身份标识号(ID)、姓名、电话、电子邮箱、身份证号、银行卡号、账户余额等信息。
时间: 2024-06-09 13:09:51 浏览: 49
以下是一个简单的银行账户管理系统程序,包括添加账户、查看账户、删除账户和修改账户信息等功能。
```python
class Account:
def __init__(self, id, name, phone, email, id_card, card_num, balance):
self.id = id
self.name = name
self.phone = phone
self.email = email
self.id_card = id_card
self.card_num = card_num
self.balance = balance
class Bank:
def __init__(self):
self.accounts = []
def add_account(self, account):
self.accounts.append(account)
def view_account(self, id):
for account in self.accounts:
if account.id == id:
print("ID:", account.id)
print("Name:", account.name)
print("Phone:", account.phone)
print("Email:", account.email)
print("ID Card:", account.id_card)
print("Card Number:", account.card_num)
print("Balance:", account.balance)
return
print("Account not found.")
def delete_account(self, id):
for account in self.accounts:
if account.id == id:
self.accounts.remove(account)
print("Account deleted.")
return
print("Account not found.")
def modify_account(self, id, name=None, phone=None, email=None, id_card=None, card_num=None, balance=None):
for account in self.accounts:
if account.id == id:
if name:
account.name = name
if phone:
account.phone = phone
if email:
account.email = email
if id_card:
account.id_card = id_card
if card_num:
account.card_num = card_num
if balance:
account.balance = balance
print("Account modified.")
return
print("Account not found.")
```
使用示例:
```python
bank = Bank()
# 添加账户
account1 = Account("1001", "Alice", "1234567890", "alice@example.com", "123456789012345678", "1111111111111111", 1000)
bank.add_account(account1)
# 查看账户
bank.view_account("1001")
# 修改账户
bank.modify_account("1001", phone="0987654321", balance=2000)
bank.view_account("1001")
# 删除账户
bank.delete_account("1001")
bank.view_account("1001")
```
输出:
```
ID: 1001
Name: Alice
Phone: 1234567890
Email: alice@example.com
ID Card: 123456789012345678
Card Number: 1111111111111111
Balance: 1000
Account modified.
ID: 1001
Name: Alice
Phone: 0987654321
Email: alice@example.com
ID Card: 123456789012345678
Card Number: 1111111111111111
Balance: 2000
Account not found.
```
阅读全文