Automatic calculation of

python payments, each account can query the consumer details, the specific contents are as follows:


function to two files: a similar wallet function, deposit the money; another record for each spending uses

 /usr/bin/env Python import #! CPickle as p with open ('','w') as f: p.dump (10000, f) with open ('record.txt','w') as f: pass 


to realize the function of

 #!! /usr/bin/env Python #coding:utf8 import cPickle as P import time date = time.strftime ('%Y%m%d') def (save_money): sav_count=int (raw_input ('save money:) = raw_input (sav_comment)'doing what:') with open ('') as f: balance (f) = p.load new_bal = balance + sav_count (open' with','w') as f: p.dump (new_bal, f) content ='%-12s%-8s%-8s%-10s%-25sn'% (date,'N/A', sav_count, new_bal, sav_comment) with open ('record.txt','a') as f: f.write (content) def (spend_money): spe_count=int (raw_input ('spend money:) = raw_input (spe_comment)'doing what: with (open')'') as f: balance (f) = p.load new_bal = balance - spe_count with open ('','w') as f: p.dump (new_bal, f) with open ('record.txt','a') as f: content ='%-12s%-8s%-8s%-10s%-25sn'% (date, spe_count,'N/A', new_bal, spe_comment) f.write (content) def (query_info): line ='='*63 content ='%sn%-12s%-8s%-8s%-10s%-25s'% (line,'Date','Cost','Save','Balance','Comment') with OP En ('') as f: new_bal = p.load (f) print'New balance: new_bal print content with', open ('record.txt') as f: for line in f: print line def show_menu (prompt):'0':'spend_money':'1' = ''save_money''2':'query_info''3':'quit' while True: 'CMDs={'0': spend_money,'1': save_money.'2': query_info} choice = raw_input ('which do you want to do%s: if choice?'%prompt) not in'012': break CMDs[choice] (if) __name__=='__main__': show_menu (pre>, 

3) < / procedures are improved, such as the two files in the form of parameters passed, will simplify the code.

is the whole content of this article, I hope to help you, and hope that you can support a lot of scripting home.

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:Python implementation of the daily bookkeeping program | Script Home

You may also be interested in these articles!