失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python人名查电话(字典)_python检索用人名查电话_创建一个将人名用作键的字典后 输入

python人名查电话(字典)_python检索用人名查电话_创建一个将人名用作键的字典后 输入

时间:2023-01-16 18:46:43

相关推荐

python人名查电话(字典)_python检索用人名查电话_创建一个将人名用作键的字典后 输入

创建了将人名用作键的字典,输入姓名查找值,返回错误。

代码:

people={

'Alice': {

'phone': '6789',

'addr': 'Ruan road 23'

},

'Mary':{

'phone': '8769',

'addr': 'Foo drive 66'

},

'Jay': {

'phone': '6666',

'addr': 'Bar street 88'

}

}

labels={

'phone':'phone number',

'addr':'address'

}

name=input('Name:')

request=input('phone number(p) or address(a)?')

if request=='p':key='phone'

if request=='a':key='addr'

if name in people: print("{}'s {} is {}.".format(name,labels[key],people[name][key]))

错误:

D:\anaconda2-5.3\python.exe C:\Users\59131\.IntelliJIdea.2\config\plugins\python\helpers\pydev\pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 55756 --file C:/Users/59131/.IntelliJIdea.2/config/scratches/04dict1.py

pydev debugger: process 23116 is connecting

Connected to pydev debugger (build 182.4892.20)

Name:Jay

Traceback (most recent call last):

File "C:\Users\59131\.IntelliJIdea.2\config\plugins\python\helpers\pydev\pydevd.py", line 1664, in

main()

File "C:\Users\59131\.IntelliJIdea.2\config\plugins\python\helpers\pydev\pydevd.py", line 1658, in main

globals = debugger.run(setup['file'], None, None, is_module)

File "C:\Users\59131\.IntelliJIdea.2\config\plugins\python\helpers\pydev\pydevd.py", line 1068, in run

pydev_imports.execfile(file, globals, locals) # execute the script

File "C:/Users/59131/.IntelliJIdea.2/config/scratches/04dict1.py", line 20, in

name=input('Name:')

File "", line 1, in

NameError: name 'Jay' is not defined

python人名查电话(字典)_python检索用人名查电话_创建一个将人名用作键的字典后 输入姓名查找值 返回错误......

如果觉得《python人名查电话(字典)_python检索用人名查电话_创建一个将人名用作键的字典后 输入》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。