欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python 模擬銀行轉(zhuǎn)賬功能過(guò)程詳解

 更新時(shí)間:2019年08月06日 11:04:54   作者:851096287  
這篇文章主要介紹了python 模擬銀行轉(zhuǎn)賬功能過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

首先畫出流程圖,流程圖與現(xiàn)實(shí)代碼有出入,因?yàn)閯傞_(kāi)始畫流程圖的時(shí)候,有些東西沒(méi)考慮進(jìn)去,后來(lái)寫著寫著就慢慢能想起來(lái)并實(shí)現(xiàn)了。

另有一點(diǎn)經(jīng)驗(yàn)推薦給新手朋友,如果說(shuō)碰到一個(gè)項(xiàng)目無(wú)從下手的話,就先慢慢去寫,寫著寫著你就會(huì)往下寫了,真的,親身實(shí)踐。望大神勿噴~

#!/usr/bin/env python
#encoding:utf-8
import re
import pickle
import time
def getUser():
  '''從數(shù)據(jù)文件里獲取銀行卡用戶信息'''
  with open('cardinfo.db','r') as f:
    return pickle.load(f)
def panDing():
  '''判定用戶銀行卡信息跟密碼信息的準(zhǔn)確性'''
  while True:
    user_dict=getUser()
    print user_dict
    card_num=raw_input('請(qǐng)輸入您的19位銀行卡號(hào)(只包含數(shù)字):')#獲取用戶卡號(hào)
    if re.match('\d{19}',card_num) and card_num in user_dict:#判斷卡號(hào)是否匹配
      card_passwd=(raw_input('請(qǐng)輸入您的銀行卡密碼:'))
      # 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']:#判定密碼對(duì)錯(cuò)
        break
      else:
        print '密碼錯(cuò)誤!'
        continue
    else:
      print '您輸入的銀行卡信息有誤!'
  return card_num

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

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

        while True:
          tr_balance = int(raw_input('請(qǐng)輸入轉(zhuǎn)賬金額:'))
          if tr_balance <= user_dict[srcaccount]['balance']:#對(duì)比轉(zhuǎn)賬金額跟賬戶余額
            break
          else:
            print '轉(zhuǎn)賬金額大于余額,請(qǐng)重新輸入余額!'
        break
      else:
        print '卡號(hào)錯(cuò)誤,請(qǐng)重新輸入!'
    else:
      print '卡號(hào)不對(duì)'
  print '轉(zhuǎn)入的賬戶為:%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 '轉(zhuǎn)入的賬戶為:%s ,轉(zhuǎn)入的金額為:%s' % (target_account, tr_balance)
  # print '轉(zhuǎn)入賬戶為:%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轉(zhuǎn)入到賬戶%s中%s人民幣' % (time.strftime('%Y-%m-%d %H:%M:%S'),srcaccount,target_account,tr_balance),f)
    print '%s 賬戶%s轉(zhuǎn)入到賬戶%s中%s人民幣' % (time.strftime('%Y-%m-%d %H:%M:%S'),srcaccount,target_account,tr_balance)




def quXian(user_card):
  '''用戶取現(xiàn)操作'''
  user_dict = getUser()
  while True:
    qx_balance=raw_input('請(qǐng)輸入取現(xiàn)金額:')
    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 取現(xiàn)人民幣 %s' % (time.strftime('%Y-%m-%d %H:%M:%S'), user_card,qx_balance))
          print '%s 賬戶[%s]取現(xiàn)人民幣%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('請(qǐng)確認(rèn)操作:(轉(zhuǎn)賬請(qǐng)按1,取現(xiàn)請(qǐng)按 2,余額查詢請(qǐng)按3,退出請(qǐng)按4):')
    if re.match('[1234]',choose_num):#根據(jù)用戶選擇類型判斷執(zhí)行方法
      if re.match('[1234]',choose_num).group() == '1':#轉(zhuǎn)帳
        zhuanZhang(user_card)
      elif re.match('[1234]',choose_num).group() == '2':#取現(xiàn)
        quXian(user_card)
      elif re.match('[1234]',choose_num).group() == '3':#余額查詢
        chaBalance(user_dict, user_card)
      else:#退出
        break
if __name__ == '__main__':
  run()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Django博客系統(tǒng)注冊(cè)之創(chuàng)建用戶模塊應(yīng)用

    Django博客系統(tǒng)注冊(cè)之創(chuàng)建用戶模塊應(yīng)用

    本文主要介紹了Django博客系統(tǒng)注冊(cè)之創(chuàng)建用戶模塊應(yīng)用,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Python調(diào)整數(shù)組形狀如何實(shí)現(xiàn)

    Python調(diào)整數(shù)組形狀如何實(shí)現(xiàn)

    這篇文章主要介紹了Python調(diào)整數(shù)組形狀如何實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2022-12-12
  • Python datetime模塊使用方法小結(jié)

    Python datetime模塊使用方法小結(jié)

    這篇文章主要介紹了Python datetime模塊使用方法小結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • python里對(duì)list中的整數(shù)求平均并排序

    python里對(duì)list中的整數(shù)求平均并排序

    本文主要記述了使用Python將list重點(diǎn)整數(shù)求平均值之后在進(jìn)行排列的過(guò)程,并把代碼分享給大家,希望大家能給鼓鼓掌~~~
    2014-09-09
  • python實(shí)現(xiàn)json轉(zhuǎn)yolo格式

    python實(shí)現(xiàn)json轉(zhuǎn)yolo格式

    在目標(biāo)檢測(cè)數(shù)據(jù)集處理中,我們經(jīng)常會(huì)遇到標(biāo)簽之間不同格式的轉(zhuǎn)化,本文主要介紹了python實(shí)現(xiàn)json轉(zhuǎn)yolo格式,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-12-12
  • 如何利用Python 進(jìn)行邊緣檢測(cè)

    如何利用Python 進(jìn)行邊緣檢測(cè)

    本文主要介紹了關(guān)于邊緣檢測(cè)的知識(shí),包括邊緣檢測(cè)的理論以及如何使用 Python 實(shí)現(xiàn)邊緣檢測(cè),希望對(duì)您的學(xué)習(xí)有所幫助。
    2020-10-10
  • 解決python 使用openpyxl讀寫大文件的坑

    解決python 使用openpyxl讀寫大文件的坑

    這篇文章主要介紹了解決python 使用openpyxl讀寫大文件的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • Python 通過(guò)爬蟲(chóng)實(shí)現(xiàn)GitHub網(wǎng)頁(yè)的模擬登錄的示例代碼

    Python 通過(guò)爬蟲(chóng)實(shí)現(xiàn)GitHub網(wǎng)頁(yè)的模擬登錄的示例代碼

    這篇文章主要介紹了Python 通過(guò)爬蟲(chóng)實(shí)現(xiàn)GitHub網(wǎng)頁(yè)的模擬登錄的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Python RuntimeWarning:invalid value encountered in double_scalars處理

    Python RuntimeWarning:invalid value encounter

    這篇文章主要介紹了Python RuntimeWarning:invalid value encountered in double_scalars處理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Python調(diào)用百度AI實(shí)現(xiàn)身份證識(shí)別

    Python調(diào)用百度AI實(shí)現(xiàn)身份證識(shí)別

    這篇文章主要介紹了Python通過(guò)調(diào)用百度AI的文字識(shí)別功能實(shí)現(xiàn)對(duì)身份證進(jìn)行識(shí)別,代碼具有一定的學(xué)習(xí)價(jià)值,感興趣的朋友一起來(lái)看看效果吧
    2021-12-12

最新評(píng)論