python模拟银行系统实验报告
Python模拟银行系统实验报告
一、实验目的
本实验旨在通过使用Python语言编写一个简单的银行系统程序,掌握Python语言的基本语法和面向对象编程思想,加深对Python编程的理解和应用。
二、实验环境
本实验在Windows 10操作系统下进行,使用Python 3.7.4版本进行编程。
三、实验步骤
1. 创建一个BankAccount类,定义账户属性和方法。
```python
class BankAccount:
def __init__(self, name, balance):
self.name = name
self.balance = balance
def deposit(self, amount):
银行汽车贷款 self.balance += amount
def withdraw(self, amount):
if amount > self.balance:
print("Insufficient balance!")
else:
self.balance -= amount
def get_balance(self):
return self.balance
```
2. 创建一个BankSystem类,定义系统属性和方法。
```python
class BankSystem:
def __init__(self):
self.accounts = []
def add_account(self, account):
self.accounts.append(account)
def find_account(self, name):
for account in self.accounts:
if account.name == name:
return account
return None
def transfer_money(self, sender_name, receiver_name, amount):
sender_account = self.find_account(sender_name)
receiver_account = self.find_account(receiver_name)
if sender_account is None or receiver_account is None:
print("Account not found!")
return
if _balance() < amount:
print("Insufficient balance!")
return
sender_account.withdraw(amount)
receiver_account.deposit(amount)
```
3. 创建一个BankUI类,定义用户界面和交互方法。
```python
class BankUI:
def __init__(self, bank_system):
self.bank_system = bank_system
def run(self):
while True:
print("1. Create account")
print("2. Deposit money")
print("3. Withdraw money")
print("4. Check balance")
print("5. Transfer money")
print("6. Exit")
choice = input("Enter your choice: ")
if choice == "1":
ate_account()
elif choice == "2":
self.deposit_money()
elif choice == "3":
self.withdraw_money()
elif choice == "4":
self.check_balance()
elif choice == "5":
ansfer_money()
elif choice == "6":
break
def create_account(self):
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论