【发布时间】:2016-02-21 06:22:25
【问题描述】:
我想制作一个字典,然后使用用户输入来打印键的值
编辑:我使用的是 Python 3.4.4 并感谢纠正语法和句法错误的用户
*我尝试使用 -input()- 但没有运气 *我找到了这段代码:
usrInp = 'z' #default value z so that while works first time
exDict = {} #initializing empty dict
while usrInp == 'z':
key = input('enter key : ')
val = input('enter val : ')
exDict[key] = val
usrInp = input('Enter z to continue adding, else any input to exit : ')
print(exDict)
但这不是我想要的。我的目标是做这样的事情:
dictionary{
1:"Number one"
2:"Number two"
3:"Number three"
}
#Asking for user input code here
print() #Print the value of the key here
【问题讨论】:
标签: python dictionary output user-input