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\.IntelliJIdea2018.2\config\plugins\python\helpers\pydev\pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 55756 --file C:/Users/59131/.IntelliJIdea2018.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\.IntelliJIdea2018.2\config\plugins\python\helpers\pydev\pydevd.py", line 1664, in

main()

File "C:\Users\59131\.IntelliJIdea2018.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\.IntelliJIdea2018.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/.IntelliJIdea2018.2/config/scratches/04dict1.py", line 20, in

name=input('Name:')

File "", line 1, in

NameError: name 'Jay' is not defined

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值