功能要求:
1.额度15000
2.可以体现,手续费是5%
3每月最后一天是出账单,写入一个文件
4.记录每月日常消费流水(每天的没笔消费)
5.写出来本期还款
python源代码:
#!/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() ###################################################
原文地址:http://3971212.blog.51cto.com/3961212/1632154