Python實(shí)現(xiàn)銀行賬戶(hù)資金交易管理系統(tǒng)-創(chuàng)新互聯(lián)

用類(lèi)和對(duì)象實(shí)現(xiàn)一個(gè)銀行賬戶(hù)的資金交易管理, 包括存款、取款和打印交易詳情, 交易詳情中包含每次交易的時(shí)間、存款或者取款的金額、每次交易后的余額。
如:

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶(hù)于互聯(lián)網(wǎng)時(shí)代的吳橋網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

下面按照要求定義一個(gè)賬戶(hù) Account 類(lèi)。賬戶(hù) Account 類(lèi)的屬性:

1. 當(dāng)前賬戶(hù)金額                               money
2. 當(dāng)前賬戶(hù)交易日志                        account_logs 


賬戶(hù) Account 類(lèi)的方法:

1. 存錢(qián)                                             deposit()無(wú)返回值
2. 取錢(qián)                                             withdrawl()無(wú)返回值
3. 打印交易詳情                               transaction_log()無(wú)返回值 


案例代碼如下:

#coding: utf-8
import time
import prettytable as pt
money = 0
acount_logs = []
class Account:
 def __init__(self):
 global money
 self.money = money
 self.acount_logs = acount_logs
 def deposit(self):
 amount = float(input('存入金額:'))
 self.money += amount
 self.write_log(amount,'轉(zhuǎn)入')
 def withdrawl(self):
 amount = float(input('取出金額:'))
 if amount > self.money:
  print('余額不足')
 else:
  self.money -= amount
  self.write_log(amount,'取出')
 def transaction_log(self):
 tb = pt.PrettyTable()
 tb.field_names = ["交易日期","摘要","金額","幣種","余額"]
 for info in self.acount_logs:
  if info[1] =='轉(zhuǎn)入':
  amount = '+{}'.format(info[2])
  else:
  amount = '-{}'.format(info[2])
  tb.add_row([info[0],info[1],amount,'人民幣',info[3]])
  print(tb)
 def write_log(self,amout,handle):
 create_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
 data =[create_time,handle,amout,self.money]
 self.acount_logs.append(data)
def show_menu():
 """ 顯示菜單欄 """
 menu = """
====================銀行賬戶(hù)資金交易管理====================
0: 退出
1:存款
2: 取款
3: 打印交易詳情
===========================================================
 """
 print(menu)
if __name__ == '__main__':
 show_menu()
 account = Account()
 while True:
 choice = int(input("請(qǐng)輸入您的選擇: "))
 if choice == 0:
  exit(0)
  print("退出系統(tǒng)")
 elif choice == 1:
  flag = True
  while flag:
  account.deposit()
  flag = True if input("是否繼續(xù)存款(Y|N): ").lower()== 'y' else False
 elif choice == 2:
  flag = True
  while flag:
  account.withdrawl()
  flag = True if input("是否繼續(xù)取款(Y|N): ").lower()== 'y' else False
 elif choice == 3:
  account.transaction_log()
 else:
  print("請(qǐng)選擇正確的編號(hào)")

分享題目:Python實(shí)現(xiàn)銀行賬戶(hù)資金交易管理系統(tǒng)-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://muchs.cn/article48/ddhchp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航微信小程序、品牌網(wǎng)站制作電子商務(wù)、建站公司、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)