2011-03-30 52 views
-1

程序應該接受文件名作爲輸入,然後打印三個數字顯示:如何開始創建字數統計程序?

  1. 的行數
  2. 計數的單詞的文件中的字符
  3. 計數。

我真的不知道從哪裏開始這個問題。請幫忙。

+2

這功課嗎? – Wrikken 2011-03-30 00:18:32

+0

我首先打開一個文件並計算單詞。如果你要發佈你所有的任務,那麼至少*試着寫一些東西,沒有人會爲你寫作業。 – 2011-03-30 00:18:48

+1

老實說,Python中的所有需求都是相當簡單的。谷歌一點,在每一個工作,然後把它放在一起。 – 2011-03-30 00:21:22

回答

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