已有一个由若干个姓名和电话号码构成的通讯录,输入姓名,在通讯录中查找对应的电话号码并输出,若该姓名不在通讯录中则显示提示信息“not found”,继续查询直到姓名输入0结束。 【待完善的源程序】 tele = {'xiaohong':'12121212', 'xiaohua':'34561234', 'xiaoma':'23451234','yuanyuan':'12345678'} while True: username = input("input the username to search: ") if username == '0': print('byebye') __________ if username __________ tele: print("{}'s phone number is {}".format(username, tele[username])) else: print("not found")
时间: 2023-08-18 21:07:07 浏览: 226
第一个空需要填写 `break`,即 `print('byebye')\nbreak`。第二个空需要填写 `in`,即 `if username in tele:`。完整的程序如下:
```python
tele = {'xiaohong':'12121212', 'xiaohua':'34561234', 'xiaoma':'23451234','yuanyuan':'12345678'}
while True:
username = input("input the username to search: ")
if username == '0':
print('byebye')
break
if username in tele:
print("{}'s phone number is {}".format(username, tele[username]))
else:
print("not found")
```
阅读全文
相关推荐












