今早在博客园和大家分享了一道昨晚微博中看到的小学奥数题,后来有朋友给出了答案.然后我尝试用python解答它. 原题是这样的: 数学题:好事好 + 要做好 = 要做好事,求 “好.事.做.要”的值分别是多少? 以下解题思路: list1=[0,1,2,3,4,5,6,7,8,9] for h in list1: for s in list1: for z in list1: for y in list1: if (h*100+s*10+h)+(y*100+z*10+h)==(y*1000+z*1
__author__ = 'Administrator' import codecs def blocks(file, size=65536): while True: b = file.read(size) if not b: break yield b with codecs. open('h:/iis/u_ex141026.log', 'r','gbk', 'ignore') as f: print( sum(bl.count("\n") for bl in blocks(f))