Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Using isupper(), islower(), isdigit(), len, and a variable for the symbol

ID: 3924093 • Letter: P

Question

PYTHON

Using isupper(), islower(), isdigit(), len, and a variable for the symbols, create a program that will ask a user to create a password that follows the following criteria:

Password length must be at least 8 characters long

Passwords must contain at least one number (1, 2, 3, 4, 5, 6, 7, 8, 9, 0)

Passwords must contain at least one lowercase letter (a, b, c, etc.)

Passwords must contain at least one uppercase letter (A, B, C, etc.)

Passwords must contain at least one of the following: ! @ # $ % & _ =

Please clarify where I went wrong in my test code below:

def numbers(password):

       digit = 0

       for i in range(0, len(password)):

             if password[i].isalnum() == True:

                  digit = 1

      else:

            print(“password doesn’t contain at least one number”)

def main():

    # Prompt user for password entry

    password = input("Please enter a password. ")

    numbers(password)

main()

Explanation / Answer

you may try the below code

import pwd

def checkPassword(password):
  
#Validate the password
  
if len(password) < 8:
# Password is too short
print("Your password must contain 8 characters")
return False
elif not pwd.findall(r'd+', password):
# Missing a number
print("You have to include a number in your password.")
return False
elif not pwd.findall(r'[A-Z]+', password):
# Missing at least one capital letter
print("You have to include a capital letter in your password.")
return False
else:
# Meets given criteria
print("Meets given criteria")
return True

# Promt user to enter valid password
passwordValid = False
while not passwordValid:
password = input("Enter password: ")
passwordValid = checkPassword(password)

In your code you didn`t follow idendatation correctly check it once