Skip to content

Commit 8baba53

Browse files
committed
complete 0007
1 parent d5f1730 commit 8baba53

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎jiangqideng/000.ipynb‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,50 @@
453453
" img = Image.open(os.path.join(root, f))\n",
454454
" img = img.resize([64, 100]).save(os.path.join(root, 'rs_' + f), 'jpeg')"
455455
]
456+
},
457+
{
458+
"cell_type": "markdown",
459+
"metadata": {},
460+
"source": [
461+
"### 第0007题\n",
462+
"有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。"
463+
]
464+
},
465+
{
466+
"cell_type": "code",
467+
"execution_count": 31,
468+
"metadata": {
469+
"collapsed": false
470+
},
471+
"outputs": [
472+
{
473+
"name": "stdout",
474+
"output_type": "stream",
475+
"text": [
476+
"file_count, code_line_count, blank_line_count, comment_line_count: \n",
477+
"893 36136 10000 18544\n"
478+
]
479+
}
480+
],
481+
"source": [
482+
"code_path = r'C:\\Users\\jiang\\Documents\\MATLAB' #matlab files\n",
483+
"import os\n",
484+
"file_count, code_line_count, blank_line_count, comment_line_count = 0, 0, 0, 0\n",
485+
"for root, dirs, files in os.walk(code_path):\n",
486+
" for f in files:\n",
487+
" if f.endswith('.m'):\n",
488+
" file_count += 1\n",
489+
" with open(os.path.join(root, f), 'r') as cur_f:\n",
490+
" for line in cur_f:\n",
491+
" if line.strip().startswith('%'):\n",
492+
" comment_line_count += 1\n",
493+
" elif line.isspace():\n",
494+
" blank_line_count += 1\n",
495+
" else:\n",
496+
" code_line_count += 1\n",
497+
"print \"file_count, code_line_count, blank_line_count, comment_line_count: \"\n",
498+
"print file_count, code_line_count, blank_line_count, comment_line_count"
499+
]
456500
}
457501
],
458502
"metadata": {

0 commit comments

Comments
 (0)