【问题标题】:How to go about creating a word count program?如何着手创建字数统计程序?
【发布时间】:2011-07-25 17:27:51
【问题描述】:

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

  1. 行数
  2. 字数
  3. 文件中的字符数。

我真的不知道从哪里开始回答这个问题。请帮忙。

【问题讨论】:

  • 我会先打开一个文件并数单词。如果你要发布你在那里完成的每一项作业,那么至少尝试写点东西,没有人会为你写作业。
  • 老实说,您的所有需求在 Python 中都相当简单。谷歌一下,研究每一个,然后把它们放在一起。
  • 不是家庭作业,只是想自学一点,但会做。
  • 别指望我们会做你的功课......我们不能教你非常基本的教程东西......这有点懒......
  • @kris:向同侪压力低头 +1。 ;-)

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


【解决方案1】:

这里有一个伪代码可以帮助您入门。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多