python - 如何检测特定单词以使其成为正确答案?
问题描述
我正在制作一个类似于家庭争执的程序,用户需要根据他选择的主题猜测正确答案。如果他只输入 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 - 如何更改google colab上使用的python版本
- docker-compose - 使用带有挂载到符号链接的 Docker 卷,但它也将数据持久化到主机。为什么?
- arrays - 角度迭代模型中的数组
- javascript - 当我发出发布请求时,React Native 返回 [未处理的承诺拒绝:TypeError:网络请求失败]
- mongodb - 在 mongodb 中使用聚合从两个集合中检索数据时出现问题
- python - 对内部 numpy 数组进行类迭代?任务?
- linux - 监控配置参数 - 组?
- javascript - 修复 React onDragExit 和 onDrop 事件在 Chrome 中不起作用
- html - 上传的图像未以 Safari 为中心
- reactjs - 错误:未捕获 [不变违规:对象作为 React 子对象无效