为什么我的for循环没有返回任何东西?

2024-04-16 12:27:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚开始自学编程,我在一个Jupyter笔记本上用python3.0(Anaconda发行版)编写了一个小程序,它应该接收一个单词,并返回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)

Tags: and程序jsonenglish编程笔记本jupyteranaconda