python设计银行柜台储蓄业务数据清单代码
时间: 2023-09-12 20:10:01 浏览: 155
好的,以下是一个简单的Python代码示例,用于设计银行柜台储蓄业务数据清单:
```
class BankAccount:
def __init__(self, account_number, balance=0):
self.account_number = account_number
self.balance = balance
self.transactions = []
def deposit(self, amount):
self.balance += amount
self.transactions.append(+amount)
def withdraw(self, amount):
if self.balance < amount:
return "Insufficient balance"
else:
self.balance -= amount
self.transactions.append(-amount)
return "Transaction successful"
def get_balance(self):
return self.balance
def get_transactions(self):
return self.transactions
account = BankAccount("1234567890")
account.deposit(500)
print(account.get_balance())
print(account.get_transactions())
account.withdraw(200)
print(account.get_balance())
print(account.get_transactions())
```
这段代码定义了一个名为 BankAccount 的类,其中包含存款、取款、获取余额和获取交易清单等方法。在这个示例中,我们创建了一个账户对象,对其进行了一些操作,并打印了余额和交易清单。
阅读全文