Answer to Question #235982 in Python for Meek

Question #235982

Prompts the user for a password. Check if the password is valid where a valid password has the following criteria. It must be at least 5 characters long. It must start with either a c or a 5. It must contain at least one special character from &,@,# and %


1
Expert's answer
2021-09-11T14:25:18-0400
def CheckPassword(password):
    if len(password) < 5:
        raise ValueError('The password must be at least 5 characters long')
    if password[0] != 'c' and password[0] != '5':
        raise ValueError('The password must start with either a c or a 5')
    for ch in ['&', '@', '#', '%']:
        if ch in password:
            return
    raise ValueError('The password must contain at least one special character from &,@,# and %')

try:
    password = input('Input password: ')
    CheckPassword(password)
    print('The password is valid')
except ValueError as e:
    print('Error:', e)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS