在过去的两个星期里,我一直在想你能帮忙吗。在
我试图从文本文件中计算平均单词长度和句子长度。我只是不知道该怎么办。我刚开始使用在主文件中调用的函数。在
我的主文件是这样的import Consonants
import Vowels
import Sentences
import Questions
import Words
""" Vowels """
text = Vowels.fileToString("test.txt")
x = Vowels.countVowels(text)
print str(x) + " Vowels"
""" Consonats """
text = Consonants.fileToString("test.txt")
x = Consonants.countConsonants(text)
print str(x) + " Consonants"
""" Sentences """
text = Sentences.fileToString("test.txt")
x = Sentences.countSentences(text)
print str(x) + " Sentences"
""" Questions """
text = Questions.fileToString("test.txt")
x = Questions.countQuestions(text)
print str(x) + " Questions"
""" Words """
text = Words.fileToString("test.txt")
x = Words.countWords(text)
print str(x) + " Words"
我的一个函数文件是这样的:
^{pr2}$
我想知道如何计算单词长度作为我导入的函数?我试着使用其他一些线程,但它们不适合我。在