帮我写一段银行管理系统使用python
时间: 2023-10-24 13:10:51 浏览: 79
基于python的银行管理系统
好的,以下是一段银行管理系统的Python代码示例:
```python
# 银行账户类
class Account:
def __init__(self, name, balance):
self.name = name
self.balance = balance
def withdraw(self, amount):
if self.balance < amount:
print("余额不足!")
else:
self.balance -= amount
print("取款成功,当前余额为:", self.balance)
def deposit(self, amount):
self.balance += amount
print("存款成功,当前余额为:", self.balance)
# 银行类
class Bank:
def __init__(self):
self.accounts = []
def add_account(self, account):
self.accounts.append(account)
def get_account(self, name):
for account in self.accounts:
if account.name == name:
return account
return None
# 程序入口
if __name__ == "__main__":
bank = Bank()
bank.add_account(Account("张三", 5000))
bank.add_account(Account("李四", 3000))
bank.add_account(Account("王五", 10000))
while True:
name = input("请输入您的姓名:")
account = bank.get_account(name)
if account is None:
print("该账户不存在,请检查账户名!")
continue
operation = input("请选择操作类型(1.查询余额,2.取款,3.存款,4.退出程序):")
if operation == "1":
print("当前余额为:", account.balance)
elif operation == "2":
amount = int(input("请输入取款金额:"))
account.withdraw(amount)
elif operation == "3":
amount = int(input("请输入存款金额:"))
account.deposit(amount)
elif operation == "4":
break
else:
print("非法操作,请检查输入!")
print("程序已退出!")
```
以上代码是一个简单的银行管理系统,支持账户余额查询、取款、存款等功能。你可以根据自己的需求进行修改和扩展。
阅读全文