即使y应该等于x,它也不起作用

问题描述 投票:1回答:1
def word(x):
    print(x)
    s=open("words.txt","r")

words.txt是.txt文件中的单词列表

这里,当y == x时,代码未执行

    for d,y in enumerate(s):
        if y==x:
            print (d)
            return d
    return False 
    s.close()

意义.txt具有.txt文件中单词的含义

def meaning(y):
    p=open("meaning.txt","r")
    n=p.readlines()
    print(n[y])

def Main():
    wird=input("Enter the word")
    k=open("new.txt","w")
    k.close()
    a=word(str(wird))
    print(a)
    if a==False:
        print("WOrd not found!!")
    else:
        meaning(a)

Main()
python dictionary
1个回答
0
投票

发现一个小小的错误! if y==x:必须更改为if d==x:。然后就可以了。我检查了它的工作原理。枚举函数的元组的第二个成员y表示数组的索引。

但是关于您问题的第二部分,我无法理解您的问题。更多解释将有助于回答。

© www.soinside.com 2019 - 2024. All rights reserved.