题解 | #禁止重复注册#
禁止重复注册
https://www.nowcoder.com/practice/43acd439112c4b85a9168ad3dd7e2bd1
def func_lower(name_list): #整个函数专门用来将列表小写 name_list = [name_list[i].lower() for i in range(len(name_list))] return name_list current_users = ['Niuniu', 'Niumei', 'GURR', 'LOLO'] current_users_lower = func_lower(current_users) #不改变原列表,创建一个新列表装小写成员 new_users = ['GurR', 'Niu Ke Le', 'LoLo', 'Tuo Rui Chi'] new_users_lower = func_lower(new_users) for i in range(len(new_users)): if new_users_lower[i] in current_users_lower: print(f'The user name {new_users[i]} has already been registered! Please change it and try again!') #对照小写列表和原列表两个,根据位置相同去原列表找到元素,按要求打印出来 else: print(f'Congratulations, the user name {new_users[i]} is available!')