功能要求:
1.额度 15000
2.可以提现,手续费5%
3.每月月底出账单.
4.记录流水(日,月)
5.提供还款接口
6.每月10号还款,逾期未还,按欠款额的5%收利息
#!/usr/bin/python #-*- coding:utf-8 -*- import time,os,glob from datetime import date, timedelta try: # os.path.exists('depot.txt') f=open('depot.txt','r') except IOError: f=open('depot.txt','w') f.write('15000') f.close() finally: f.close() if os.path.isdir('log'): pass else: os.mkdir('log') class mycard: '''the card problem from http://bbs.pyshell.com/forum.php?mod=viewthread&tid=39&extra=''' ff=open('depot.txt','r') depot=int(ff.readlines()[0]) ff.close() def __init__(self,money): self.money=int(money) print '你的额度:15000 余额为%d\n' %(mycard.depot) try: f1=open('/tmp/log/%s.log' %date.today(),'r') except IOError: f1=open('/tmp/log/%s' %date.today(),'w+') finally: f1.close() def Pay(self): '''Pay by Card''' mycard.depot -= self.money print '你消费了%d\n' %self.money f=open('depot.txt','w') f.write(str(mycard.depot)) f.close() now=time.ctime().split(' ') log=open('%s-%s-%s' %(now[4],now[1],now[2]),'w+') log.write('%s %s %s %s 你消费了%d\n' %(now[4],now[1],now[2],now[3],self.money)) log.close() def getcash(self): '''enchashment''' mycard.depot -= self.money print '取走了%d,手续费%d,实得金额%d,剩余%d\n' %(self.money,self.money*5/100,self.money-self.money*5/100,mycard.depot) f=open('depot.txt','w') f.write(str(mycard.depot)) f.close() now=time.ctime().split(' ') log=open('%s-%s-%s' %(now[4],now[1],now[2]),'w+') log.write('%s %s %s %s 取走了%d,手续费%d,实得金额%d,剩余%d\n' %(now[4],now[1],now[2],now[3],self.money,self.money*5/100,self.money-self.money*5/100,mycard.depot)) log.close() def save(self): '''save money''' mycard.depot += self.money print '你存入了%d,现在总计可用金额%d\n' %(self.money,mycard.depot) f=open('depot.txt','w') f.write(str(mycard.depot)) f.close() now=time.ctime().split(' ') log=open('%s-%s-%s' %(now[4],now[1],now[2]),'w+') log.write('%s %s %s %s 你存入了%d,现在总计可用金额%d\n' %(now[4],now[1],now[2],now[3],self.money,mycard.depot)) log.close() def sendlog(self): '''月底发送账单''' today=str(date.today()).split('-') os.chdir('log') logname=glob.glob('%s-%s*' %(today[0],today[1])) for i in logname: content=open(i,'r').readlines for ii in content: print ii if __name__ == '__main__': today=date.today() tomorrow=today+timedelta(1) if str(today).split('-')[1] != str(tomorrow).split('-')[1]: sendlog() UserOpt=raw_input(' 1 存款\n 2 取现\n 3 刷卡消费\n') if UserOpt==str(1): money=input('请输入金额:\n') mycard(money).save() elif UserOpt==str(2): money=input('请输入金额:\n') mycard(money).getcash() elif UserOpt==str(3): money=input('请输入金额:\n') mycard(money).Pay() 还有少许功能未实现.