"无法分配到功能调用" if语句

时间:2018-03-19 11:34:07

标签: python python-3.x

我正在尝试创建一个带有段落的程序,然后显示单词计数,单词的平均长度以及每个单词出现的次数。然而,当试图实现发现每个单词出现次数的部分时,发生了错误:"不能分配给函数调用"我已经看过其他问题,但是我已经无法适应它了。错误发生在" word_amount(字位)+ = 1"线。

passage = "this is a test to test this program"
words = passage.split()
wordcount = len(words)
print(passage)
print("Number of words:",wordcount)
wordlength = list(map(len, words))
avwordlength = (sum(wordlength))/wordcount
print("Average word length:",avwordlength)
checked_words = []
word_amount = []
for x in range(wordcount):
        currentword = words(x)
        if currentword in checked_words:
                wordposition = checked_words.index(currentword)
                word_amount(wordposition) += 1
        else:
                checked_words.append(currentword)
                word_amount.append(1)
print(checked_words)
print(word_amount)

1 个答案:

答案 0 :(得分:0)

圆括号用于函数,这就是错误告诉您它正在尝试将单词数量解释为函数的原因。你需要使用方括号,也可以使用上面三行的单词