列表

详情


NP45. 禁止重复注册

描述

创建一个依次包含字符串'Niuniu'、'Niumei'、'GURR'和'LOLO'的列表current_users,
创建一个依次包含字符串'GurR'、'Niu Ke Le'、'LoLo'和'Tuo Rui Chi'的列表new_users,
使用for循环遍历new_users,如果遍历到的新用户名在current_users中,
使用print()语句一行输出类似字符串'The user name GurR has already been registered! Please change it and try again!'的语句,
否则使用print()语句一行输出类似字符串'Congratulations, the user name Niu Ke Le is available!'的语句。(注:用户名的比较不区分大小写)

输入描述

输出描述

按题目描述进行输出即可。
The user name GurR has already been registered! Please change it and try again!
Congratulations, the user name Niu Ke Le is available!
The user name LoLo has already been registered! Please change it and try again!
Congratulations, the user name Tuo Rui Chi is available!

原站题解

Python 解法, 执行用时: 9ms, 内存消耗: 2964KB, 提交时间: 2022-07-26

# coding=utf-8
current_users = ['Niuniu','Niumei','GURR','LOLO']
new_users = ['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
for j in new_users:
    flag=0
    for i in current_users:
        if i.lower()==j.lower():
            print("The user name {} has already been registered! Please change it and try again!".format(j))
            flag=1
            break;
    if flag==0:
        print("Congratulations, the user name {} is available!".format(j))

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-07-11

current_users = ['Niuniu','Niumei','GURR','LOLO']
new_users = ['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
for name in new_users:
    if name.upper() in current_users:
        print('The user name {} has already been registered! Please change it and try again!'.format(name))
    else:
        print('Congratulations, the user name {} is available!'.format(name))

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-06-21

current_users = ["Niuniu","Niumei","GURR","LOLO"]
new_users = ['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
lower_current_users = [i.lower() for i in current_users]
for user in new_users:
    if user.lower() in lower_current_users :
        print('The user name {} has already been registered! Please change it and try again!'.format(user))
        
    else:
        print('Congratulations, the user name {} is available!'.format(user))

Python 解法, 执行用时: 10ms, 内存消耗: 2836KB, 提交时间: 2022-06-10

a = ["Niuniu", "Niumei", "GURR", "LOLO"]
b = ["GurR", "Niu Ke Le", "LoLo", "Tuo Rui Chi"]
for x in b:
    for y in a:
        if x.upper() == y.upper():
            print("The user name {} has already been registered! Please change it and try again!".format(x))
            break;
    else:
        print("Congratulations, the user name {} is available!".format(x))

Python 解法, 执行用时: 10ms, 内存消耗: 2840KB, 提交时间: 2022-07-16

current_users =['Niuniu','Niumei','GURR','LOLO']
new_users =['GurR','Niu Ke Le','LoLo','Tuo Rui Chi']
# new_users = [i.upper() for i in new_users]
for i in new_users:
    if i.upper() in current_users:
        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)

上一题