如何创建字数统计程序?

时间:2011-03-30 00:15:54

标签: python python-3.x word-count

程序应接受文件名作为输入,然后打印三个数字显示:

  1. 行数
  2. 单词数量
  3. 文件中的字符数。
  4. 我真的不知道从哪里开始这个问题。请帮忙。

1 个答案:

答案 0 :(得分:4)

这是一个帮助您入门的伪代码。

open file handle
set counter_line=0
set counter_word=0
set counter_char=0
while iterate file
   increment counter_line
   split line into array
   counter_word += length of split array
   counter_char += length of line
end while
close file handle