题解 | #梦想的大学#

梦想的大学

http://www.nowcoder.com/practice/f0de95ee47c844e78d70a21f7b2c7911

# 创建一个名为survey_dict的空字典
survey_dict = {}
while 1:
    print('If you have the chance, which university do you want to go to most?')
    print('What is your name?')
    # 将读取到的字符串存储在变量name中
    name = input()
    print('Which university do you want to go to most?')
    # 将读取到的字符串存储在变量university中
    university = input()
    # 把键-值对name: university存储在字典survey_dict中
    survey_dict[name] = university
    print("Is there anyone who hasn't been investigated yet?")
    result = input()
    if result == 'No':
        break
for name in sorted(survey_dict, reverse=False):
    print(f"I'am {name}. I'd like to go to {survey_dict[name]} if I have the chance!")
    
    
    
    
全部评论
为啥把键值对name:university存储到字典survey_dict中这步要写为 survey_dict[name]=university 而不是 survey_dict={name: university} 当写后者时,显示用例不通过,大佬能答疑下吗?
点赞 回复 分享
发布于 2022-07-15 10:17

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务