日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Python基础项目实践之:面向对象方法实现模拟银行管理系统

發布時間:2025/3/15 windows 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python基础项目实践之:面向对象方法实现模拟银行管理系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python課堂基礎實踐系列:

Python基礎項目實踐之:學生信息管理系統

python基礎項目實踐之: 學生通訊錄管理系統

Python基礎項目實踐之:面向對象方法模擬簡單計算器

Python基礎項目實踐之:面向對象方法實現模擬銀行管理系統

面向對象方法實現模擬銀行管理系統
代碼如下:

import prettytable as pt # 表格形式顯示 import timebank_log = [] # 初始化銀行交易日志class Bank:'''銀行類'''def __init__(self):"""初始化"""self.money = 0 # 封裝和初始化金額self.bank_log = bank_logdef deposit(self):"""存款"""amount = float(input("請輸入存款金額: "))self.money += amountself.write_log(amount, '轉入')def withdrawl(self):"""取款"""amount = float(input("請輸入取款金額: "))if amount > self.money:print("余額不足")else:self.money -= amountself.write_log(amount, "消費")def transaction_log(self):"""打印交易日志"""tb = pt.PrettyTable()tb.field_names = ['交易日期', '摘要', '金額', '幣種', '余額'] # 設置表頭for info in self.bank_log:# 判斷轉入還是消費,為金額前添加“+” 或“-”if info[1] == '轉入':amout = "+{}".format(info[2])else:amout = "-{}".format(info[2])tb.add_row([info[0], info[1], amout, '人民幣', info[3]])print(tb)def write_log(self, amount, handle):"""寫入日志"""# 按照指定形式獲取時間creat_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))data = [creat_time, handle, amount, self.money] # 組裝列表self.bank_log.append(data) # 寫入日志信息def display():"""顯示菜單欄"""menu = """====================銀行賬戶資金交易管理====================0:退出1:存款2:取款3:打印交易詳情=========================================================="""print(menu)if __name__ == '__main__':display() # 顯示菜單account = Bank() # 創建對象while True:choice = int(input("請輸入您的選擇: "))if choice == 0:exit(0)print("退出系統")elif choice == 1:flag = Truewhile flag:# deposit_money = float(input('存款金額: '))account.deposit()flag = True if input("是否繼續存款(yes/no): ").lower() == "yes" else Falseelif choice == 2:flag = Truewhile flag:# wd_money = float(input("取款金額: "))account.withdrawl()flag = True if input("是否繼續取款(yes/no):").lower() == 'yes' else Falseelif choice == 3:account.transaction_log()else:print("請重新選擇正確的序號") import prettytable as pt # 表格形式顯示 import timebank_log = [] # 初始化銀行交易日志class Bank:'''銀行類'''def __init__(self):"""初始化"""self.money = 0 # 封裝和初始化金額self.bank_log = bank_logdef deposit(self):"""存款"""amount = float(input("請輸入存款金額: "))self.money += amountself.write_log(amount, '轉入')def withdrawl(self):"""取款"""amount = float(input("請輸入取款金額: "))if amount > self.money:print("余額不足")else:self.money -= amountself.write_log(amount, "消費")def transaction_log(self):"""打印交易日志"""tb = pt.PrettyTable()tb.field_names = ['交易日期', '摘要', '金額', '幣種', '余額'] # 設置表頭for info in self.bank_log:# 判斷轉入還是消費,為金額前添加“+” 或“-”if info[1] == '轉入':amout = "+{}".format(info[2])else:amout = "-{}".format(info[2])tb.add_row([info[0], info[1], amout, '人民幣', info[3]])print(tb)def write_log(self, amount, handle):"""寫入日志"""# 按照指定形式獲取時間creat_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))data = [creat_time, handle, amount, self.money] # 組裝列表self.bank_log.append(data) # 寫入日志信息def display():"""顯示菜單欄"""menu = """====================銀行賬戶資金交易管理====================0:退出1:存款2:取款3:打印交易詳情=========================================================="""print(menu)if __name__ == '__main__':display() # 顯示菜單account = Bank() # 創建對象while True:choice = int(input("請輸入您的選擇: "))if choice == 0:exit(0)print("退出系統")elif choice == 1:flag = Truewhile flag:# deposit_money = float(input('存款金額: '))account.deposit()flag = True if input("是否繼續存款(yes/no): ").lower() == "yes" else Falseelif choice == 2:flag = Truewhile flag:# wd_money = float(input("取款金額: "))account.withdrawl()flag = True if input("是否繼續取款(yes/no):").lower() == 'yes' else Falseelif choice == 3:account.transaction_log()else:print("請重新選擇正確的序號") import prettytable as pt # 表格形式顯示 import timebank_log = [] # 初始化銀行交易日志class Bank:'''銀行類'''def __init__(self):"""初始化"""self.money = 0 # 封裝和初始化金額self.bank_log = bank_logdef deposit(self):"""存款"""amount = float(input("請輸入存款金額: "))self.money += amountself.write_log(amount, '轉入')def withdrawl(self):"""取款"""amount = float(input("請輸入取款金額: "))if amount > self.money:print("余額不足")else:self.money -= amountself.write_log(amount, "消費")def transaction_log(self):"""打印交易日志"""tb = pt.PrettyTable()tb.field_names = ['交易日期', '摘要', '金額', '幣種', '余額'] # 設置表頭for info in self.bank_log:# 判斷轉入還是消費,為金額前添加“+” 或“-”if info[1] == '轉入':amout = "+{}".format(info[2])else:amout = "-{}".format(info[2])tb.add_row([info[0], info[1], amout, '人民幣', info[3]])print(tb)def write_log(self, amount, handle):"""寫入日志"""# 按照指定形式獲取時間creat_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))data = [creat_time, handle, amount, self.money] # 組裝列表self.bank_log.append(data) # 寫入日志信息def display():"""顯示菜單欄"""menu = """====================銀行賬戶資金交易管理====================0:退出1:存款2:取款3:打印交易詳情=========================================================="""print(menu)if __name__ == '__main__':display() # 顯示菜單account = Bank() # 創建對象while True:choice = int(input("請輸入您的選擇: "))if choice == 0:exit(0)print("退出系統")elif choice == 1:flag = Truewhile flag:# deposit_money = float(input('存款金額: '))account.deposit()flag = True if input("是否繼續存款(yes/no): ").lower() == "yes" else Falseelif choice == 2:flag = Truewhile flag:# wd_money = float(input("取款金額: "))account.withdrawl()flag = True if input("是否繼續取款(yes/no):").lower() == 'yes' else Falseelif choice == 3:account.transaction_log()else:print("請重新選擇正確的序號")

總結

以上是生活随笔為你收集整理的Python基础项目实践之:面向对象方法实现模拟银行管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。