题解 | #禁止重复注册#
禁止重复注册
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)
