您好,登錄后才能下訂單哦!
首先畫出流程圖,流程圖與現(xiàn)實(shí)代碼有出入,因?yàn)閯傞_始畫流程圖的時(shí)候,有些東西沒考慮進(jìn)去,后來寫著寫著就慢慢能想起來并實(shí)現(xiàn)了。
另有一點(diǎn)經(jīng)驗(yàn)推薦給新手朋友,如果說碰到一個(gè)項(xiàng)目無從下手的話,就先慢慢去寫,寫著寫著你就會(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í)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。