Skip to content

Commit 2869926

Browse files
committed
Finish 0007
1 parent 5dea837 commit 2869926

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎JiYouMCC/0007/0007.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
4+
CODE_PATH = os.path.join(os.path.dirname(__file__), '..')
5+
6+
code_files = []
7+
code_line_count = 0
8+
code_blank_line_count = 0
9+
code_comment_line_count = 0
10+
11+
12+
def walk(rootDir):
13+
global code_files
14+
for lists in os.listdir(rootDir):
15+
path = os.path.join(rootDir, lists)
16+
if os.path.isdir(path):
17+
walk(path)
18+
else:
19+
if os.path.splitext(lists)[1].upper() == '.PY':
20+
code_files.append(path)
21+
22+
walk(CODE_PATH)
23+
for code_file in code_files:
24+
file = open(code_file)
25+
for line in file:
26+
code_line_count += 1
27+
if line == '\n':
28+
code_blank_line_count += 1
29+
if line.replace(' ', '').replace('\t', '')[0] == '#':
30+
code_comment_line_count += 1
31+
print '文件数量:', len(code_files)
32+
print '代码行数:', code_line_count
33+
print '空行行数:', code_blank_line_count
34+
print '注释行数:', code_comment_line_count

‎JiYouMCC/0007/readme.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**第 0007 题:**有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。

0 commit comments

Comments
 (0)