30,358
社区成员
创建一个依次包含字符串'Niuniu'、'Niumei'、'GURR'和'LOLO'的列表current_users,
再创建一个依次包含字符串'GurR'、'Niu Ke Le'、'LoLo'和'Tuo Rui Chi'的列表new_users,
使用for循环遍历new_users,如果遍历到的新用户名在current_users中,
则使用print()语句一行输出类似字符串'The user name GurR has already been registered! Please change it and try again!'的语句,
否则使用print()语句一行输出类似字符串'Congratulations, the user name Niu Ke Le is available!'的语句。(注:用户名的比较不区分大小写)
无
按题目描述进行输出即可。
The user name GurR has already been registered! Please change it and try again!
Congratulations, the user name Niu Ke Le is available!
The user name LoLo has already been registered! Please change it and try again!
Congratulations, the user name Tuo Rui Chi is available!
将new_users中的元素全部改成小写字母,存储到new_users_L。用lower()函数将for循环遍历的元素改成小写字母。
current_users = ['Niuniu','Niumei','GURR','LOLO']
new_users = ['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
current_users_L = [i.lower() for i in current_users]
for i in new_users:
if i.lower() in current_users_L:
print('The user name ' + i + ' has already been registered! Please change it and try again!')
else:
print('Congratulations, the user name ' + i + ' is available!')
禁止重复注册_牛客题霸_牛客网 (nowcoder.com)