题解 | #禁止重复注册#

禁止重复注册

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

创建现有用户和新用户两个列表

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循环将小写化的新用户列表内元素与小写化的现有用户列表元素对比并判断

for i in new_users:
    if i.lower() in current_users_l:
        print('The user name %s has already been registered! Please change it and try again!' % i)
    else:
        print('Congratulations, the user name %s is available!' %i)
全部评论

相关推荐

在考古的丘比特很冷艳:[牛泪我横向一周多自动挂了,面试答的还行,感觉挂的莫名其妙
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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