第一个python程序-blog数目统计
第一个python程序,统计2009年日志数目。统计blog数目
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1 filename = "C://blog-total.txt"
2 file = open(filename,'r')
3 sum =0
4 while 1:
5 line= file.readline()
6 print(line,end='')
7 if(len(line)==0):
8 break
9 left =line.find('(')
10 right =line.rfind(')')
11 sum += int( line+1:right])
12
13 file.close()
14 print("\nYou have written {t} blogs".format(t=sum))
15
结果:
>>>
2009年12月 (6)
2009年11月 (6)
2009年10月 (6)
2009年9月 (16)
2009年8月 (16)
2009年7月 (11)
2009年6月 (12)
2009年5月 (11)
2009年4月 (6)
2009年3月 (13)
2009年2月 (3)
2009年1月 (1)
You have written 107 blogs
页:
[1]