Password Validator
Validate practice passwords with character rules. Students compare a strong-rule conjunction with a looser medium branch and inspect allowed special symbols.
1# Take password2password = input("Enter password: ")34# Validate5has_upper = any(c.isupper() for c in password)6has_lower = any(c.islower() for c in password)7has_digit = any(c.isdigit() for c in password)8has_special = any(c in "!@#$%^&*" for c in password)9length_ok = len(password) >= 81011if length_ok and has_upper and has_lower and has_digit and has_special:12 print("Strong password")13elif length_ok and (has_upper or has_lower) and has_digit:14 print("Medium password")15else:16 print("Weak password")
Output
Enter password: MyPass123! Strong password
In this one
- Combine explicit requirements
- Distinguish strong and medium policies
- Restrict the special-symbol set
How it works
- 1
Calculate case, digit, symbol, and length booleans.
- 2
Test the full strong conjunction first.
- 3
Otherwise test the medium rule before choosing Weak.
Edge cases
Does a space satisfy has_special?
Does a space satisfy has_special?
No. It is not in the explicit symbol string.
Can a password without a digit be Medium?
Can a password without a digit be Medium?
No. The medium branch requires a digit.
What's going on
Strong requires eight characters, both letter cases, a digit, and a symbol from !@#$%^&*. Medium requires length, at least one letter case, and a digit.
Unlike the five-check scoring lesson, this is a branch policy rather than counting passed booleans. Spaces do not satisfy the listed-symbol rule, though they count toward length. The labels are classroom feedback, not a security guarantee or password-storage method.
Does a space satisfy has_special? No. It is not in the explicit symbol string.
Can a password without a digit be Medium? No. The medium branch requires a digit.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What distinguishes the strong branch?
Pick an answer to check it.
Question 2
Does a space satisfy has_special?
Pick an answer to check it.
Questions people ask
Does a space satisfy has_special?
No. It is not in the explicit symbol string.
Can a password without a digit be Medium?
No. The medium branch requires a digit.
What distinguishes the strong branch?
Every listed requirement must pass.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum