python - 不在终端输出。终端中没有要求输入
问题描述
所以刚刚开始学习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))
这可能出了什么问题
解决方案
在提供的代码中,您只定义函数,不执行函数。您需要调用该函数(在定义它之后)。例如:
import json
data = json.load(open("076 data.json"))
def Dictionary():
key = input("Enter the word here : ")
print(data[key])
Dictionary()
推荐阅读
- c# - 创建与 ML.Net Pipelines 一起使用的自定义分类器
- python - numba prange 给出了错误的结果
- java - 如何从服务方法延迟加载集合?
- java - 在 Spring Boot OAuth2 服务器上验证 Cron 作业
- mysql - 在 laravel eloquent 中使用带有 group by 的子查询
- python - 运行分离的散景服务器
- bdd - 是否可以在 specflow 中为场景生成示例表?
- angular - 量角器:只能为页面启用虚拟时间,不能为工作人员启用
- dockerfile - Docker distroless image 如何将自定义证书添加到信任库?
- python - 以 10 为底的 int() 的无效文字:Python 中的“x”错误?