码迷,mamicode.com
首页 > 编程语言 > 详细

信用卡交易系统 Python

时间:2015-12-06 17:37:40      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/env python
#--*-- coding:utf-8 --*--

#safe_float 的函数主体
def safe_float(obj): ‘safe version of float()‘ try: retval = float(obj) except (ValueError,TypeError),diag: retval = str(diag) return retval def main(): ‘handles all the data processing‘ log = open(‘cardlog.txt‘,‘w‘) #记录log try: ccfile = open(‘carddata.txt‘,‘r‘) except IOError,e: log.write(‘no txns this month\n‘) log.close() return txns = ccfile.readlines() ccfile.close() total = 0.00 log.write(‘account log:\n‘) for eachTxn in txns: result = safe_float(eachTxn) if isinstance(result,float): #检查是否为float total += result log.write(‘data... processed\n‘)#写入 else: log.write(‘ignore:%s‘%result) print ‘$%s.2f (new balance)‘%(total) log.close() if __name__ == ‘__main__‘: main()

 

信用卡交易系统 Python

标签:

原文地址:http://www.cnblogs.com/magicpower/p/5023857.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!