生活随笔
收集整理的這篇文章主要介紹了
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_log
def 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
:account
.deposit
()flag
= True if input("是否繼續存款(yes/no): ").lower
() == "yes" else Falseelif choice
== 2:flag
= Truewhile flag
: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_log
def 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
:account
.deposit
()flag
= True if input("是否繼續存款(yes/no): ").lower
() == "yes" else Falseelif choice
== 2:flag
= Truewhile flag
: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_log
def 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
:account
.deposit
()flag
= True if input("是否繼續存款(yes/no): ").lower
() == "yes" else Falseelif choice
== 2:flag
= Truewhile flag
:account
.withdrawl
()flag
= True if input("是否繼續取款(yes/no):").lower
() == 'yes' else Falseelif choice
== 3:account
.transaction_log
()else:print("請重新選擇正確的序號")
總結
以上是生活随笔為你收集整理的Python基础项目实践之:面向对象方法实现模拟银行管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。