首页 > 解决方案 > 不在终端输出。终端中没有要求输入

问题描述

所以刚刚开始学习python 3。所以我们得到了包含单词含义的json文件(这是一本英文词典)。所以我们有一个练习,我们必须输入这个词,我们会得到它的定义。但是当我执行代码时,终端是空的,我没有得到任何输出。这是代码: -

import json
data = json.load(open("076 data.json"))

def Dictionary(Word):
    key = str(input("Enter the word here : "))
    return data[key]
    print(Dictionary(key))

这可能出了什么问题

标签: pythonjsondictionaryinputterminal

解决方案


在提供的代码中,您只定义函数,不执行函数。您需要调用该函数(在定义它之后)。例如:

import json
data = json.load(open("076 data.json"))

def Dictionary():
    key = input("Enter the word here : ")
    print(data[key])

Dictionary()

推荐阅读