我将使用什么 while 循环条件来检测输入全部小写?

What while loop condition will I use to detect the input all lowercase?

我将使用什么 while 循环条件来检测输入全部小写?

FirstName = input("Enter your First Name: ")
LastName = input("Enter your Last Name: ")

while FirstName.lower() and LastName.lower():
    print("Your First and Last Name should be typed in a lowercase letter")
    FirstName = input("Enter your First Name: ")
    LastName = input("Enter your Last Name: ")

print("Welcome")

感谢您的帮助!我们将不胜感激。

它总是帮助我开始在代码中非常明确地表达我的意图。您的意图是一直循环,直到用户为他们的名字和姓氏输入所有小写字母,因此 while not all_lower_case_entered 继续循环。在您的循环中,您的目的是收集用户数据并检查是否 full_name.islower()。如果不是,则打印您的错误消息,如果是,请将 all_lower_case_entered 设置为 True。

示例:

all_lower_case_entered = False

while not all_lower_case_entered:
    first_name = input("Enter your first Name: ")
    last_name = input("Enter your last Name: ")
    
    full_name = first_name + last_name

    if not full_name.islower():
        print("Your first and last names should be typed in all lowercase letters.")
    else:
        all_lower_case_entered = True

print("Welcome")