亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

python 模擬銀行轉賬功能過程詳解

系統 1915 0

首先畫出流程圖,流程圖與現實代碼有出入,因為剛開始畫流程圖的時候,有些東西沒考慮進去,后來寫著寫著就慢慢能想起來并實現了。

python 模擬銀行轉賬功能過程詳解_第1張圖片

另有一點經驗推薦給新手朋友,如果說碰到一個項目無從下手的話,就先慢慢去寫,寫著寫著你就會往下寫了,真的,親身實踐。望大神勿噴~

            
#!/usr/bin/env python
#encoding:utf-8
import re
import pickle
import time
def getUser():
  '''從數據文件里獲取銀行卡用戶信息'''
  with open('cardinfo.db','r') as f:
    return pickle.load(f)
def panDing():
  '''判定用戶銀行卡信息跟密碼信息的準確性'''
  while True:
    user_dict=getUser()
    print user_dict
    card_num=raw_input('請輸入您的19位銀行卡號(只包含數字):')#獲取用戶卡號
    if re.match('\d{19}',card_num) and card_num in user_dict:#判斷卡號是否匹配
      card_passwd=(raw_input('請輸入您的銀行卡密碼:'))
      # print '輸入的密碼是:%s,類型為:%s' % (int(card_passwd),type(int(card_passwd)))
      # print '存的密碼是:%s,類型為:%s' % (user_dict[card_num]['password'],type(user_dict[card_num]['password']))
      if int(card_passwd) == user_dict[card_num]['password']:#判定密碼對錯
        break
      else:
        print '密碼錯誤!'
        continue
    else:
      print '您輸入的銀行卡信息有誤!'
  return card_num

def zhuanZhang(srcaccount):
  '''用戶轉賬操作'''

  user_dict = getUser()
  while True:
    target_account = raw_input('請輸入目標賬戶:')
    if re.match('\d{19}', target_account) :
      if target_account in user_dict: # 判斷卡號是否匹配

        while True:
          tr_balance = int(raw_input('請輸入轉賬金額:'))
          if tr_balance <= user_dict[srcaccount]['balance']:#對比轉賬金額跟賬戶余額
            break
          else:
            print '轉賬金額大于余額,請重新輸入余額!'
        break
      else:
        print '卡號錯誤,請重新輸入!'
    else:
      print '卡號不對'
  print '轉入的賬戶為:%s ,金額為:%s' % (target_account,tr_balance)
  print '原賬戶為:%s ,余額為:%s' % (srcaccount,user_dict[srcaccount]['balance'])
  print user_dict
  user_dict[srcaccount]['balance']=user_dict[srcaccount]['balance']-tr_balance
  user_dict[target_account]['balance'] = user_dict[target_account]['balance'] + tr_balance
  print '轉入的賬戶為:%s ,轉入的金額為:%s' % (target_account, tr_balance)
  # print '轉入賬戶為:%s ,余額為:%s' % (target_account, user_dict[target_account]['balance'])
  print '原賬戶為:%s ,余額為:%s' % (srcaccount, user_dict[srcaccount]['balance'])
  print user_dict
  with open('cardinfo.db','w') as f:
    pickle.dump(user_dict,f)
  with open('op.log','a+') as f:
    f.writelines('%s 賬戶%s轉入到賬戶%s中%s人民幣' % (time.strftime('%Y-%m-%d %H:%M:%S'),srcaccount,target_account,tr_balance),f)
    print '%s 賬戶%s轉入到賬戶%s中%s人民幣' % (time.strftime('%Y-%m-%d %H:%M:%S'),srcaccount,target_account,tr_balance)




def quXian(user_card):
  '''用戶取現操作'''
  user_dict = getUser()
  while True:
    qx_balance=raw_input('請輸入取現金額:')
    if re.match('\d+',qx_balance):
      print user_dict[user_card]['balance']
      if int(qx_balance) <= user_dict[user_card]['balance']:
        user_dict[user_card]['balance'] = user_dict[user_card]['balance'] - int(qx_balance)
        print user_dict
        with open('cardinfo.db', 'w') as f:
          pickle.dump(user_dict, f)
        with open('op.log', 'a') as f:
          f.write('%s 賬戶 %s 取現人民幣 %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), user_card,qx_balance))
          print '%s 賬戶[%s]取現人民幣%s圓' % (time.strftime('%Y-%m-%d %H:%M:%S'), user_card,qx_balance)
        break
      else:
        print '余額不夠!'
    else:
      print '輸入的格式有誤'
  # with open('cardinfo.db','r') as f:
  #   print pickle.load(f)
  # with open('op.log','r') as f:
  #   print pickle.load(f)

def chaBalance(user_dict,user_card):

  print '賬戶余額為:%s ' % user_dict[user_card]['balance']

def run():
  user_card = panDing()
  print user_card
  while True:
    user_dict=getUser()
    # print '賬戶余額為:%s ' % user_dict[user_card]['balance']
    choose_num=raw_input('請確認操作:(轉賬請按1,取現請按 2,余額查詢請按3,退出請按4):')
    if re.match('[1234]',choose_num):#根據用戶選擇類型判斷執行方法
      if re.match('[1234]',choose_num).group() == '1':#轉帳
        zhuanZhang(user_card)
      elif re.match('[1234]',choose_num).group() == '2':#取現
        quXian(user_card)
      elif re.match('[1234]',choose_num).group() == '3':#余額查詢
        chaBalance(user_dict, user_card)
      else:#退出
        break
if __name__ == '__main__':
  run()
          

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 午夜一级精品免费毛片 | 视频一区二区国产无限在线观看 | 亚洲欧美中文字幕 | 狠狠色丁香久久婷婷 | 久草精品免费 | 337p色噜噜人体大胆欧美 | 久久久精品久久久久三级 | 国产免费人成在线视频视频 | 欧美乱子伦一区二区三区 | 亚洲国产精品久久久久网站 | 久久99国产乱子伦精品免费 | 欧美成人性做爰网站免费 | 日韩一区二区三区视频在线观看 | 日本人xxxxxxx中国 | 精品黑人一区二区三区 | 9久9久热精品视频在线观看 | 亚洲精品乱码久久久久久中文字幕 | 国产高清在线a视频大全凹凸 | 国产在播放一区 | a毛片在线播放 | 中国一级毛片在线观看 | 久草免费在线视频观看 | 97免费在线 | 欧美精品亚洲精品日韩专 | 日本免费不卡视频一区二区三区 | 91精东果冻蜜桃星空麻豆 | 免费观看一级成人毛片软件 | 日本xxxwww在线观看免费 | 日韩精品免费一级视频 | 亚洲精品一区二区在线观看 | 天天操人人射 | 国产成人啪午夜精品网站男同 | 中日韩欧美一级毛片 | 在线精品一区二区三区 | 亚洲精品日本 | 成 人 黄 色视频免费播放 | 日日狠狠久久偷偷四色综合免费 | 色妞在线 | 4hu影院永久在线播放 | 国产视频手机在线观看 | 奇米影视狠狠狠天天777 |