Challenge 2: Password strength

Suggested time: 20 minutes

A programmer is designing a program which should ask the user to enter a password and then display a message saying how secure that password is.

The program currently contains errors, but it should function as shown below:

Example program output for a password which passes all 5 checks

There are 5 conditions the password is checked for:

  1. Does the password contain a capital letter?
  2. Does the password contain a lower case letter?
  3. Does the password contain any punctuation?
  4. Does the password contain any numbers?
  5. Is the password more than 5 characters long?

The strength of the password is determined by how many of these conditions are met:

Number of conditions metPassword strength
0Dangerously insecure
Password strength

Using the file below:

Amend the lines at the bottom of the code to give the:

  • fix the syntax error on original line 8
    PUNCTUATION = "!"£$%^&*(){}[]:@~;'#<>?"
  • fix the syntax error on original line 26
    define containsAnyOf(pPassword, pCharacters):
  • fix the NameError error on original line 48
    return (Strength)
  • fix the logic error to call the calcPasswordStrength function on original line 56
    passwordStrength = calcPasswordStrength
  • fix the syntax error on original line 59
    print("Your password is " + PASSWORD_DESCRIPTIONS[passwordStrength)

Do not add any additional functionality

If this was a real question it would tell you to save your code as but you might want to save your code so you can show your teacher or come back to it later by pressing Ctrl + S or clicking on the icon that looks like this:

Save / share icon in lets you save your code