A password is text used to decide whether an input meets a stated strength or validity rule. A Boolean result reports True or False. section 3.3.2
Build password checks by making the rule explicit:
- Start with a simple rule: reject the exact strings "password" and "qwerty". section 3.3.2
- Return a Boolean from a predicate such as is_strong_password(password). section 3.3.2
- Strengthen the rule by requiring an uppercase character, a number, and a special symbol or punctuation mark. section 3.3.2
- Test rejected, accepted, and boundary-like examples rather than trusting generated code automatically. section 3.3.2
Testing a stronger rule
A check rejects "Leo" because it lacks the required character categories, accepts "N3w Y0rk J375$", and rejects "N3w Y0rk J375" when punctuation is required. section 3.3.2
import string
def is_strong_password(password):
"""
A strong password has at least one uppercase character,
at least one number, and at least one punctuation.
Return True if the password is a strong password, False if not.
"""
return any(char.isupper() for char in password) and \
any(char.isdigit() for char in password) and \
any(char in string.punctuation for char in password)
Use the complete Python version to inspect uppercase, digit, and punctuation checks; importing string is necessary before using string.punctuation. section 3.3.2
def is_valid_password(password):
if len(password) <= 8:
if any(char.isupper() for char in password):
if any(char.islower() for char in password):
if any(char.isdigit() for char in password):
return True
return False
return False
return False
Use the faulty exercise implementation to diagnose a length-condition error while practicing multi-criterion validation. section 8.8








