写一段银行管理系统的python代码
时间: 2023-06-14 16:05:07 浏览: 189
下面是一个简单的银行管理系统的 Python 代码示例:
```python
class Bank:
def __init__(self, name):
self.name = name
self.accounts = {}
def create_account(self, account_number, initial_balance):
if account_number in self.accounts:
raise ValueError("Account number already exists")
self.accounts[account_number] = initial_balance
def deposit(self, account_number, amount):
if account_number not in self.accounts:
raise ValueError("Account does not exist")
self.accounts[account_number] += amount
def withdraw(self, account_number, amount):
if account_number not in self.accounts:
raise ValueError("Account does not exist")
if self.accounts[account_number] < amount:
raise ValueError("Insufficient balance")
self.accounts[account_number] -= amount
def get_balance(self, account_number):
if account_number not in self.accounts:
raise ValueError("Account does not exist")
return self.accounts[account_number]
```
这个银行管理系统只包含了几个基本功能,如创建账户、存款、取款和查询余额。你可以根据需要进行修改和扩展。
阅读全文