我正在做一个谜语猜谜游戏。这依赖于用户使问题正确(显然)进展,因此用户的答案必须与存储在字典中的问题答案相匹配。如果他们没有得到相同的准确措辞,这将使测验难以置信,所以是否可以添加多个版本的正确答案来涵盖这个?我正在使用一个json文件,简单的"问题"并且"回答"键。到目前为止,我有这个,(它会引发各种各样的错误!)但是,希望你能得到我所追求的一切:
[
{
"question": "I'm so fast you can't see me, though everyone else can see straight through me. I don't stop until the day you die. What am I?",
"answer": (("The blink of an eye"),("Blink of an eye"),("Blink of eye"),("Eye blink"))
}
谢谢!
答案 0 :(得分:1)
为什么不将答案存储在列表中?
{
"question": "I'm so fast you can't see me, though everyone else can see straight through me. I don't stop until the day you die. What am I?",
"answer": ["The blink of an eye","Blink of an eye","Blink of eye","Eye blink"]
}
答案 1 :(得分:0)
尝试这样的事情: 在这种情况下使用数组是不错的选择。在你的问题中,json格式是错误的。因此,您正面临着这个问题。
[{
"question": "I'm so fast you can't see me, though everyone else can see straight through me. I don't stop until the day you die. What am I?",
"answer": ["The blink of an eye", "Blink of an eye", "Eye blink"]
}]
答案 2 :(得分:0)
如果您打开其他选项而不是存储所有可能的答案,请尝试存储单个答案并比较用户对正确答案的响应之间的字符串相似性。
一些常见的相似性测量,例如Leveinstain距离应该可以很好地工作,还有一个很好的库fuzzywuzzy来处理诸如眨眼之类的情况。 vs眼睛眨眼' (订购)