python银行管理系统代码
时间: 2023-09-29 18:10:15 浏览: 162
以下是一个简单的 Python 银行管理系统代码,包括创建账户、存款、取款和查询余额功能:
```python
class BankAccount:
def __init__(self, name, balance=0.0):
self.name = name
self.balance = balance
def deposit(self, amount):
self.balance += amount
print("Deposit successful. New balance is:", self.balance)
def withdraw(self, amount):
if amount > self.balance:
print("Insufficient balance.")
else:
self.balance -= amount
print("Withdrawal successful. New balance is:", self.balance)
def check_balance(self):
print("Current balance is:", self.balance)
# 创建账户
account = BankAccount("John Doe")
# 存款
account.deposit(1000)
# 取款
account.withdraw(500)
# 查询余额
account.check_balance()
```
可以根据需要进行扩展,例如添加账户列表、转账功能等。
阅读全文
相关推荐
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)