See the work of the third lesson of the Python tutorial
First draw a flowchart, the flow chart and the actual code discrepancies, because the beginning of the drawing process, some things are not considered in, and then write to write slowly can think of and realized.
Another point of experience to recommend to novice friends, if said to encounter a project can not start, then slowly to write, write write you will write down, really, hands-on practice. Hope Big God don't squirt ~
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/8A/52/wKioL1gtdSPBHCXIAAFuGvCwcSU763.png-wh_500x0-wm_3 -wmp_4-s_1915392436.png "title=" bank withdrawal. png "alt=" wkiol1gtdspbhcxiaafugvcwcsu763.png-wh_50 "/>
#!/usr/bin/env python#encoding:utf-8import reimport pickleimport timedef getuser (): "Get bank card user information from data file" ' with open (' cardinfo.db ', ' R ') as f: return pickle.load (f) def panDing (): ' Determine the accuracy of the user's bank card information and password information ' while True: user_dict=getuser () print user_ Dict card_num=raw_input (' Please enter your 19-digit bank card number (including numbers only): ') #获取用户卡号 if re.match (' \d{19} ', Card_num) and card_num in user_dict: #判断卡号是否匹配 card_passwd= ( Raw_input (' Please enter your bank card password: ') # print ' password entered is:%s, type:%s ' % (int (CARD_PASSWD), type (int (card_passwd))) # print ' saved password is:%s, type:%s ' % (user_dict[card_num][' password '],type (user_dict[ card_num][' password ')) if int ( CARD_PASSWD) == user_dict[card_num][' password ': #判定密码对错 break else: print ' password is wrong! ' continue else: print ' The card information you entered is incorrect! ' return card_numdef zhuanzhang (Srcaccount): ' user transfer operation ' user_dict = getuser () while True: target_account = Raw_input (' Please enter target account: ') if re.match (' \d{19} ', target_ account) : if target_account in user_dict: # determine if the card number matches while True: tr_balance = int (Raw_input (' Please enter the transfer amount: ') if tr_balance <= user_dict[srcaccount][' balance ': #对比转账金额跟账户余额 break else: print ' transfer amount is greater than the balance, please re-enter the balance! ' break else: print ' card number error, please re-enter! ' else: print ' card number not ' print ' transferred to account:%s , Amount:%s ' % ( target_account,tr_balance) print ' original account:%S&NBSP;, the balance is:%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 ' transferred account:%s , the amount transferred is:%s ' % (Target_account, tr_balance) # print ' transfer to account:%s , Balance:%s ' % (target_account , user_dict[target_account][' balance ') print ' original account:%s , Balance:%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: &Nbsp; f.writelines ('%s account%s ' transferred to account%s '%s RMB ' % (time.strftime ('%y-%m-%d %h:%m:%s ') , srcaccount,target_account,tr_balance), f) print '%s Account%s is transferred to%s RMB % (time.strftime ('%y-%m-%d %h:%m:%s ') in account%s, srcaccount,target_account,tr_balance) Def quxian (User_card): "User withdrawal action" user_dict = GetUser () while true: qx_balance= Raw_input (' Please enter cash amount: ') 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 account %s cash withdrawal RMB %s ' % (time.strftime ('%y-%m-%d %h:%m:%s '), user_card,qx_balance) print '%s account [%s] withdrawals RMB%s round ' % (time.strftime ('%y-%m-%d %h:%m:%s '), user_card,qx_balance) break Else: print ' balance is not enough! ' else: print ' input format is incorrect ' # 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 ' Account balance is:%s ' &Nbsp;% user_dict[user_card][' balance ']def run (): user_card = panding () print user_card while True: user_dict=getuser () # print ' Account balance is:%s ' % user_dict[user_card][' balance '] Choose_num=raw_input (' Please confirm the operation: (Transfer please press 1, cash withdrawal please press &NBSP;2, balance enquiry Please press 3, exit please press 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 ': #取现 &NBSp; quxian (User_card) elif re.match (' [1234] ', choose_num ). Group () == ' 3 ': #余额查询 chabalance (User_dict, user_card) else: #退出 breakif __name__ == ' __main__ ': run ()
This article is from "song" blog, please be sure to keep this source http://song1230.blog.51cto.com/5595296/1873990
Python Simple analog Bank transfer function