python银行管理系统
时间: 2023-07-08 13:53:29 浏览: 66
好的,下面是一个简单的 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 self.balance < amount:
print("Withdrawal unsuccessful. Insufficient balance.")
else:
self.balance -= amount
print("Withdrawal successful. New balance is:", self.balance)
def check_balance(self):
print("Your current balance is:", self.balance)
def main():
print("Welcome to the Python Bank!")
name = input("Please enter your name: ")
account = BankAccount(name)
while True:
print("1. Check balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Quit")
choice = int(input("Enter your choice: "))
if choice == 1:
account.check_balance()
elif choice == 2:
amount = float(input("Enter amount to deposit: "))
account.deposit(amount)
elif choice == 3:
amount = float(input("Enter amount to withdraw: "))
account.withdraw(amount)
elif choice == 4:
print("Thank you for banking with us!")
break
else:
print("Invalid choice. Please try again.")
if __name__ == '__main__':
main()
```
此代码定义了一个 `BankAccount` 类来管理银行账户。在 `main()` 函数中,用户可以执行以下操作:
1. 检查余额
2. 存款
3. 取款
4. 退出程序
用户选择要执行的操作后,程序将相应地调用 `BankAccount` 类中的方法。
以上是一个简单的 Python 银行管理系统示例代码,可以根据自己的需要进行修改和扩展。