功能要求:
1.額度15000
2.能夠體現,手續費是5%
3每個月最後一天是出帳單,寫入一個文件
4.記錄每個月平常消費流水(天天的沒筆消費)python
5.寫出來本期還款app
python源代碼:ide
#!/usr/bin/env python # encoding=utf-8 # author:sihaogongyuan # date:2015-4-13 # filename:atm-py # desc:atm-py ################################################# import sys import os sys.path.append('/tmp/python/') import tab import time ################################################# credit_line=int(15000) old_money=int(15000) #print type(credit_line) #counter_fee=0.05 fee_rate=0.05 ################################################# #date=time.strftime('%Y-%m-%d %H:%M:%S') ################################################# date1=time.strftime('%Y-%m-%d-%H:%M:%S') f=file('%s.log'%(date1),'w') f.close() f=file('%s.log'%(date1),'a') f.write('交易日期\t交易摘要\t金額\t手續費\t信用額度\n') #######取現###################################### def qu_xian(): global credit_line global fee_rate #date=os.system("date '+%F:%T'") #print date date=time.strftime('%Y-%m-%d %H:%M:%S') quxian_money=int(raw_input('請輸入取現金額:').strip()) #print quxian_money,type(quxian_money) while quxian_money=='': continue #print quxian_money,type(quxian_money) if 0<quxian_money<=credit_line: #定義手續費counter_fee counter_fee=quxian_money*fee_rate credit_line=credit_line-quxian_money-counter_fee print '\033[32m已取%d元,手續費是%d元,信用額度是%d元\033[0m'%(quxian_money,counter_fee,credit_line) f.write('%s\t取現\t%s\t%d\t%d\n'%(date,quxian_money,counter_fee,credit_line)) f.flush() else: print '\033[31m取現金額%d不在信用額度內,取現失敗\033[0m'%(quxian_money) #######刷卡######################################## def shua_ka(): global credit_line #date=os.system("date '+%F:%T'") date=time.strftime('%Y-%m-%d %H:%M:%S') shuaka_money=int(raw_input('請輸入消費金額:').strip()) if 0<shuaka_money<=credit_line: credit_line=credit_line-shuaka_money print '\033[32m已消費%d元,信用額度是%d元\033[0m'%(shuaka_money,credit_line) #f.write(os.system('date'),'\t','刷卡','\t',shuaka_money,0) f.write('%s\t刷卡\t%s\t0\t%d\n'%(date,shuaka_money,credit_line)) f.flush() else: print '\033[31m消費金額%d不在信用額度內,消費失敗\033[0m'%(shuaka_money) ########存錢####################################### def cun_qian(): global credit_line #date=os.system("date '+%F:%T'") date=time.strftime('%Y-%m-%d %H:%M:%S') cun_qian_money=int(raw_input('請輸入存錢金額:').strip()) if cun_qian_money>0: credit_line=credit_line+cun_qian_money print '\033[32m存款%d成功,目前信用額度是:%d'%(cun_qian_money,credit_line) f.write('%s\t存錢\t-%s\t0\t%d\n'%(date,cun_qian_money,credit_line)) f.flush() else: print '\033[31m存取金額%d不符合規範,存款失敗\033[0m'%(cun_qian_money) ###########main#################################### print '\t歡迎來到ATM系統' while True: #credit_line=int(15000) #fee_rate=0.05 choice=raw_input('請輸入你要進行的操做(取現,消費,存錢,退出):').strip() if choice=='': continue if choice=='取現' or choice=='提現': qu_xian() continue elif choice=='刷卡' or choice=='消費': shua_ka() continue elif choice=='存錢' or choice=='存款': cun_qian() continue elif choice=='退出' or choice=='exit': break else: print '不合規的操做,請從新選擇' continue ################################################### f.write('\033[32m目前可用信用額度爲:%s\n\033[0m'%(credit_line)) f.flush() f.write('\033[32m本期還款金額爲%d\n\033[0m'%(old_money-credit_line)) f.flush() f.close() f=file('%s.log'%(date1),'r') print f.read() ###################################################