列表

详情


NP68. 毕业生就业调查

描述

又到了毕业季,牛牛作为牛客大学的学生会主席,决定对本校的应届毕业生进行就业调查。
他创建了一个依次包含字符串'Niumei'、'Niu Ke Le'、'GURR'和'LOLO'的列表survey_list,作为调查名单;
又创建了一个依次包含键-值对'Niumei': 'Nowcoder'和'GURR': 'HUAWEI'的字典result_dict,作为已记录的调查结果。
请遍历列表survey_list,如果遍历到的名字已出现在 包含字典result_dict的全部键的列表 里,
使用print()语句一行输出类似字符串'Hi, Niumei! Thank you for participating in our graduation survey!'的语句以表达感谢,
否则使用print()语句一行输出类似字符串'Hi, Niu Ke Le! Could you take part in our graduation survey?'的语句以发出调查邀请。

输入描述

输出描述

按题目描述进行输出即可。
Hi, Niumei! Thank you for participating in our graduation survey!
Hi, Niu Ke Le! Could you take part in our graduation survey?
Hi, GURR! Thank you for participating in our graduation survey!
Hi, LOLO! Could you take part in our graduation survey?

原站题解

Python 解法, 执行用时: 10ms, 内存消耗: 2832KB, 提交时间: 2022-06-10

a = ["Niumei", "Niu Ke Le", "GURR", "LOLO"];
z = {"Niumei": "Nowcoder", "GURR": "Huawei"};
for b in a:
    if b in z:
        print("Hi, {}! Thank you for participating in our graduation survey!".format(b));
    else:
        print("Hi, %s! Could you take part in our graduation survey?" % b);

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-08-04

survey_list=['Niumei','Niu Ke Le','GURR','LOLO']
result_dict={'Niumei':'Nowcoder','GURR':'HUAWEI'}
for i in survey_list:
    if i in result_dict.keys():
        print('Hi, {}! Thank you for participating in our graduation survey!'.format(i))
    else:
        print('Hi, {}! Could you take part in our graduation survey?'.format(i))
        

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-07-15

survey_list = ['Niumei','Niu Ke Le','GURR','LOLO']
result_dict = {'Niumei': 'Nowcoder','GURR': 'HUAWEI'}
for i in survey_list:
    if i in result_dict:
        print('Hi, '+i+'! Thank you for participating in our graduation survey!')
    else:
        print('Hi, '+i+'! Could you take part in our graduation survey?')

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-07-09

survey_list = ['Niumei','Niu Ke Le','GURR','LOLO']
result_dict = {'Niumei':'Nowcoder','GURR':'HUAWEI'}
for i in survey_list:
    if i in result_dict:
        print('Hi, {}! Thank you for participating in our graduation survey!'.format(i))
    else:
        print('Hi, {}! Could you take part in our graduation survey?'.format(i))



        

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-06-17

survey_list=['Niumei','Niu Ke Le','GURR','LOLO']
result_dict={'Niumei': 'Nowcoder','GURR': 'HUAWEI'}
for i in survey_list:
    for j in result_dict:
        if i==j:
            print('Hi, %s! Thank you for participating in our graduation survey!'%i)
            break
    else:
        print('Hi, %s! Could you take part in our graduation survey?'%i)

上一题