【发布时间】:2021-12-26 18:41:20
【问题描述】:
这是我的代码,我正在尝试针对包含否定词词表的 Json 文件扫描用户的输入,以获取用户输入中否定词的总和。
注意:我将用户输入放在一个列表中。
当前输出: 不会打印与以下代码相关的输出。
def SumOfNegWords(wordsInTweet):
f = open ('wordList.json')
wordList = json.load(f)
NegAmount = 0
for words in wordsInTweet: #for words in the input
if wordsInTweet in wordList['negative']:
NegAmount += 1
print("The Sum of Negative Words =", NegAmount)
else: print("No negative words found")
【问题讨论】:
-
您能否描述一下您所看到的代码有什么问题,或者是什么不工作。或者你的问题是什么?
-
当然,对不起!我没有得到与单词总和相关的输出,也没有收到错误消息“未找到否定词”。