In python, how do you check if a string has both uppercase and lowercase letters

后端 未结 4 619
独厮守ぢ
独厮守ぢ 2021-01-14 17:34

I\'ve looked at the other post similar to my question, Password check- Python 3, except my question involves checking if the password contains both uppercase and lower case

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 18:15

    Answer to question Break line not executing marked as duplicated:

    password = input('Enter your password')
    password_letters = list(password)
    upper = False
    lower = False
    name = 'Papa'
    surname = 'Johns'
    
    for letter in password_letters:
        if letter.isupper():
            upper = True
        elif letter.islower():
            lower = True
    
        if upper and lower:
            break
    
    if len(password) <= 5:
        print('password is to short')
    elif name.lower() in password.lower() or surname.lower() in password.lower():
        print('You cannot have first or last name in password')
    elif not (upper and lower):
        print('You must have both upper and lower case in password')
    else:
        print('Password is valid')
    

提交回复
热议问题