为什么我的for循环不返回任何内容?

时间:2019-12-02 17:57:07

标签: python json loops for-loop

我刚刚开始自己​​学习编程,我已经使用python 3.0(Anaconda发行版)在Jupyter笔记本中编写了一个小程序,该程序应该包含一个单词并返回JSON文件中的所有单词。与您输入的单词的押韵。我发现当我运行它时,我没有任何回报。我已经绞尽脑汁想着我在这里做错了-我敢肯定我错过了这件事。

import json

english_words = open('C:/Users/thoma/Documents/Programs/Python Programs/Rhyme Machine/words_dictionary.json', 'r')
rhymee = input('give me a word and ill return you all the words that rhyme with it. ')
rhymers = []

for word in english_words:
    if len(word) > 3 and word[-3:] == rhymee[-3:]:
        rhymers.append(word)
    else:
        pass
print(rhymers)

1 个答案:

答案 0 :(得分:-1)

该代码中没有read()函数,因此英语单词仅包含文件对象,而不包含数据。尝试先读取文件,然后进行for循环。玩耍,尝试用英语显示单词变量。

相关问题