如何在Python中对字符串实现大小写验证?

2024-05-29 07:12:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何在用户输入的密码上实现区分大小写的验证。此时,将显示批准消息,但如果输入了不带小写和大写字符的密码,则不会显示错误消息和随后的重新输入提示。有办法解决这个问题吗?你知道吗

#Password entry
def receivePassword():
    password = input("Enter a password, mane.")
    return password

#Verification of lowercase containment
def lowerCase(password):
    lcase = False
    while lcase ==False:
        for i in password:
            if ord(i) >= 97 and ord(i) <= 122:
                lcase = True
    return lcase

#Verification of uppercase containment
def upperCase(password):
    ucase = False
    while ucase ==False:
        for i in password:
            if ord(i) >= 65 and ord(i) <= 90:
                ucase = True
    return ucase

def validity(lcase,ucase):
    if lcase == True and ucase == True:
        print("That's a nice, valid, password mane.")
    while lcase !=True and ucase!= True:
        print("Re enter a password with upper and lowercase characters.")
        password = input("Enter a password, mane.")

#Top-Level Program
password = receivePassword()
lcase = lowerCase(password)
ucase = upperCase(password)
valid = validity(lcase,ucase)

Tags: andfalsetrue消息密码returnifdef

热门问题