Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 艾利夫不回来了_Python 3.x - Fatal编程技术网

Python 3.x 艾利夫不回来了

Python 3.x 艾利夫不回来了,python-3.x,Python 3.x,导入difflib 导入json 从difflib导入SequenceMatcher 从difflib导入获取\u关闭\u匹配 data=json.load(open("data.json")) #word= input("enter a word:") def tranlate(word): word = word.lower() if word in data: return data[word] elif len(get_clos

导入difflib 导入json 从difflib导入SequenceMatcher 从difflib导入获取\u关闭\u匹配

data=json.load(open("data.json"))
#word= input("enter a word:")

def tranlate(word):
    word = word.lower()

if word in data:
    return data[word]
elif len(get_close_matches(word,data.keys()))> 0 :
    x=get_close_matches(word,data.keys())[0]
       
    z = input("do u mean %s instead?Enter Y if yes or N if no" %x)
    if z.lower() ==  "y" or "yes":
        return data[x]
    elif z.lower()== "n" or "no":
        return "please enter correct word"
    else:
        return "we do not understand your entry"
else:
        
        
    return "this word does not exixt,please double check it"
#ratio = SequenceMatcher(None, a, b).ratio()

word= input("enter a word:")
print(tranlate(word))
下面的代码没有运行,并且一直在执行

if z.lower() ==  "y" or "yes":
            return data[x]
elif z.lower()== "n" or "no":
            return "please enter correct word"
        else:
            return "we do not understand your entry"

如果您的
条件不正确:

应写为:

if z.lower() ==  "y" or z.lower()== "yes":
            return data[x]
elif z.lower()== "n" or z.lower()== "no":
            return "please enter correct word"
else:
            return "we do not understand your entry"
最初,您正在执行:
z.lower()==“y”或“yes”

这导致:
“y”或“yes”
,它们总是返回true,因此它永远不会转到其他条件