首页 > 解决方案 > 如何检测特定单词以使其成为正确答案?

问题描述

我正在制作一个类似于家庭争执的程序,用户需要根据他选择的主题猜测正确答案。如果他只输入 1 个单词,我怎么能得到特定的单词?

from nltk.corpus.reader import WordListCorpusReader
import os
again = True
print("GUESSING GAME")

print(reader.words('D:/VB/topic1.txt'))
while again:
    num = int(input("PICK A NUMBER FOR THE TOPIC [1-3]: "))
    if num == 1:
        print("1. Name something people are afraid of. ")
        print("======================================")
        print("You need to guess 10 right answers in order to win. ")
        reader = WordListCorpusReader('D:/VB/topic1.txt', ['topic1.txt'])
        for i in range(0,10):
            element = (input(str(i + 1) + ". "))

topic1.txt 文件:

蜘蛛

高地

其他人

垂死

黑暗

鬼魂

国税局

一个人呆着

他们的老板或被解雇


例如,用户猜测:黑暗。在我的档案中,答案是“黑暗”。如何在不包括“The”的情况下将其声明为正确答案。另一个例子是“他们的老板”,如果用户只输入“老板”,我想做出正确的猜测

标签: python

解决方案


推荐阅读