python银行管理系统
时间: 2023-10-16 14:33:03 浏览: 48
好的,下面是一个简单的Python银行管理系统的示例:
```python
class BankAccount:
def __init__(self, name, balance):
self.name = name
self.balance = balance
self.transactions = []
def deposit(self, amount):
self.balance += amount
self.transactions.append(('deposit', amount))
def withdraw(self, amount):
if self.balance < amount:
print('Insufficient balance')
else:
self.balance -= amount
self.transactions.append(('withdraw', amount))
def get_balance(self):
return self.balance
def show_transactions(self):
for transaction in self.transactions:
print(transaction)
# 创建新账户
account = BankAccount('John Doe', 1000)
# 存款
account.deposit(500)
# 取款
account.withdraw(200)
# 显示余额
print('Balance:', account.get_balance())
# 显示交易历史
account.show_transactions()
```
该系统包括一个BankAccount类,用于表示银行账户。每个账户有一个名字,一个余额,以及一组交易记录。该类提供了存款、取款、获取余额和显示交易历史等方法。
要使用该系统,您可以创建一个新的BankAccount对象,并调用它的方法来进行存款、取款和查询余额等操作。您还可以使用show_transactions方法来查看账户的交易历史。