列表

详情


NP58. 找到HR

描述

创建一个依次包含字符串'Niuniu'、'Niumei'、'HR'、'Niu Ke Le'、'GURR' 和 'LOLO' 的列表users_list,
使用for循环遍历users_list,如果遍历到的用户名是 'HR' ,则使用print()语句一行打印字符串 'Hi, HR! Would you like to hire someone?'否则使用print()语句一行打印类似字符串 'Hi, Niuniu! Welcome to Nowcoder!' 的语句。

输入描述

输出描述

按题目描述进行输出即可。
Hi, Niuniu! Welcome to Nowcoder!
Hi, Niumei! Welcome to Nowcoder!
Hi, HR! Would you like to hire someone?
Hi, Niu Ke Le! Welcome to Nowcoder!
Hi, GURR! Welcome to Nowcoder!
Hi, LOLO! Welcome to Nowcoder!

原站题解

Python 解法, 执行用时: 9ms, 内存消耗: 2844KB, 提交时间: 2022-07-02

user_list = ['Niuniu','Niumei','HR','Niu Ke Le','GURR' ,'LOLO']
for i in user_list:
    if i=='HR':
        print("Hi, HR! Would you like to hire someone?")
    else:
        print( 'Hi, {}! Welcome to Nowcoder!'.format(i))

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

# user_list = ['Niuniu','Niumei','HR','Niu Ke Le','GURR','LOLO']
# for user in user_list:
#     if user == "HR":
#         print('Hi, %s! Would you like to hire someone?'%user)
#     else:
#         print('Hi, %s Welcome to Nowcoder!'%user)
        
users_list = ['Niuniu', 'Niumei', 'HR', 'Niu Ke Le', 'GURR', 'LOLO'] 
for i in users_list: 
    if i == "HR": print('Hi, %s! Would you like to hire someone?' % i)
    else: print('Hi, %s! Welcome to Nowcoder!' % i)
        

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

user_list = ['Niuniu', 'Niumei', 'HR', 'Niu Ke Le', 'GURR', 'LOLO']
for i in user_list:
    if i == 'HR':
        print 'Hi, HR! Would you like to hire someone?'
    else:
        print 'Hi, ' + i + '! Welcome to Nowcoder!'

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

users_list=('Niuniu','Niumei','HR','Niu Ke Le','GURR','LOLO')
for user in users_list:
    if user=='HR':
        print("Hi, HR! Would you like to hire someone?")
    else:
        print("Hi, "+user+"! Welcome to Nowcoder!")

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

users_list=['Niuniu','Niumei','HR','Niu Ke Le','GURR', 'LOLO' ]
for elem in users_list:
    if elem == 'HR':
        print('Hi, HR! Would you like to hire someone?')
        continue
    print('Hi, '+ elem + '! Welcome to Nowcoder!')

上一题