题解 | #禁止重复注册#
禁止重复注册
https://www.nowcoder.com/practice/43acd439112c4b85a9168ad3dd7e2bd1
current_users = ['Niuniu','Niumei','GURR','LOLO'] new_users = ['GurR','Niu Ke Le','LoLo','Tuo Rui Chi'] for i in new_users: flag = False for j in current_users: if i.lower() == j.lower(): flag = True if flag: print(f'The user name {i} has already been registered! Please change it and try again!') else: print(f'Congratulations, the user name {i} is available!') 要先判断完内循环对错,再输出,所有用一个局部变量存储 若先若每一个内循环都比较了就打印,则会出现很多多余语句,比如GurR与Niuniu对比,就会马上print