【发布时间】:2019-12-02 17:57:07
【问题描述】:
我刚开始自学编程,我已经使用 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)
【问题讨论】:
-
这取决于 JSON 文件的格式。请给我们举个例子。
标签: python json loops for-loop