第一个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[left+1:right])
12
13 file.close()
14 print("\nYou have written {t} blogs".format(t=sum))
15
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[left+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
本文介绍了一个简单的Python程序,用于读取指定文件中的2009年博客日志条目,并统计全年博客总数。通过解析每条记录中的月份及数量信息,最终汇总得出2009年共发表博客107篇。

被折叠的 条评论
为什么被折叠?



