在每个查询的新行上,如果名称在电话簿中没有相应的条目,请打印Not found
,否则以name=phoneNumber
格式打印全名和数字。
n=int(input())
dict={}
for i in range(0,n):
p=[]
p.append(input().split())
dict.update({p[0][0]:int(p[0][1])})
r=[]
while(1):
z=input()
if(len(z)!=0):
r.append(z)
else:
break
for l in range(0,len(r)):
if(r[l] in dict):
print(r[l]+ "=" + str(dict[r[l]]))
else:
print("Not found")
3
a 334234
b 2342342
c 425453
a
b
c
d
e
我的电脑闲置a=334234
b=2342342
c=425453
Not found
Not found
Traceback (most recent call last):
File "solution.py", line 10, in <module>
z=input()
EOFError: EOF when reading a line
答案 0 :(得分:0)
不要在built-ins之后命名变量,它们会被遮蔽。通过捕获EOFError:
来解决您的问题# d is what you called dict - which you should not
d = {}
for n in range(int(input())):
name,number = [x.strip() for x in input().strip().split()]
d[name]=number
while True:
try:
q = input()
if q in d:
print("{}={}".format(q, d[q]))
else:
print("Not found")
except EOFError:
break