我想使用users输入(current_input)并使用它访问名为(john)的字典,该字典位于一个名为(约翰·皮伊). 如果用户输入john,我希望检查for语句约翰。约翰并打印出键(x)和属性(约翰。约翰[x] )。有什么想法吗?在
import john
current_fugitive = input("Please enter the name of the fugitive: ")
if current_fugitive =="john":
for x in current_fugitive.current_fugitive:
print(x, current_fugitive.current_fugitive[x])
(编辑) 最初的代码是:
^{pr2}$
你是说这个吗?在
你不想这么做。这是初学者常犯的一个错误,即将的意思赋给变量名。不要让你的值有意义,但你的变量名应该是好的、描述性的名称,程序员可以清楚地知道,但对程序来说没有任何意义。在
很可能,
john.py
应该是john.json
,您应该这样做:相关问题 更多 >
编程相关推荐