题解 | #禁止重复注册#

禁止重复注册

http://www.nowcoder.com/practice/43acd439112c4b85a9168ad3dd7e2bd1

NP24 禁止重复注册

思路:

step1:创建两个列表;
step2:将cur列表转化为小写字母形式;
step3:遍历new_列表,对应要求,分别打印输出;

代码如下:

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 {} has already been registered! Please change it and try again!'.format(i))
    else:
        print('Congratulations, the user name {} is available!'.format(i))
全部评论
可以用f'{}'来替代 不加forma的话不会显示那是是包含和不包含的元素
点赞 回复 分享
发布于 2022-09-15 12:14 上海
不加这个format的话,会有什么影响呢? 或者有什么其他的替代方法吗?
点赞 回复 分享
发布于 2022-07-09 15:02

相关推荐

点赞 评论 收藏
分享
评论
46
5
分享

创作者周榜

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