python银行系统
时间: 2023-12-21 17:32:03 浏览: 86
python实现银行管理系统
5星 · 资源好评率100%
Python银行系统是一个用Python编写的软件系统,用于管理银行的各种业务和操作。它可以处理客户账户、存款、取款、转账、贷款、利息计算等功能。以下是一个简单的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:
print("Account already exists.")
else:
self.accounts[account_number] = initial_balance
print("Account created successfully.")
def deposit(self, account_number, amount):
if account_number in self.accounts:
self.accounts[account_number] += amount
print("Deposit successful.")
else:
print("Account does not exist.")
def withdraw(self, account_number, amount):
if account_number in self.accounts:
if self.accounts[account_number] >= amount:
self.accounts[account_number] -= amount
print("Withdrawal successful.")
else:
print("Insufficient balance.")
else:
print("Account does not exist.")
def transfer(self, from_account, to_account, amount):
if from_account in self.accounts and to_account in self.accounts:
if self.accounts[from_account] >= amount:
self.accounts[from_account] -= amount
self.accounts[to_account] += amount
print("Transfer successful.")
else:
print("Insufficient balance.")
else:
print("One or both accounts do not exist.")
def get_balance(self, account_number):
if account_number in self.accounts:
print("Account balance:", self.accounts[account_number])
else:
print("Account does not exist.")
# 创建银行对象
bank = Bank("ABC Bank")
# 创建账户
bank.create_account("1234567890", 1000)
# 存款
bank.deposit("1234567890", 500)
# 取款
bank.withdraw("1234567890", 200)
# 转账
bank.transfer("1234567890", "0987654321", 300)
# 查询余额
bank.get_balance("1234567890")
bank.get_balance("0987654321")
```
这个示例展示了一个简单的Python银行系统,包括创建账户、存款、取款、转账和查询余额等功能。你可以根据实际需求进行扩展和修改。
阅读全文