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:
There are 5 conditions the password is checked for:
- Does the password contain a capital letter?
- Does the password contain a lower case letter?
- Does the password contain any punctuation?
- Does the password contain any numbers?
- 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 met | Password strength |
0 | Dangerously insecure |
1 | Insecure |
2 | Weak |
3 | Medium |
4 | Strong |
5 | Secure |
Using the file Q02.py 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 Q02_FINISHED.py 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: