ファイルとテキストの処理2

ユーザーの指定したファイルの単語数カウントプログラムをつくってみた

import string
def numwords(s):
    list = string.split(s)
    return len(list)
txt = raw_input("fairumeiwonyuuryoku")
inp = open(txt, "r")
total = 0
for line in inp:
    total = total + numwords(line)
print "konofairunotanngosuuha%sdesu" % total
inp.close()

Thank you for telling me about your recent situation
という文を保存したファイル名を指定すると
「konofairunotanngosuuha9desu」と表示される