Basic Password Validation
Take a password string and check basic rules (length >= 8 and contains at least one digit).
IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 10 of 10
basic-password-validation.py
1# Take password2password = input("Enter password: ")34# Check rules5has_length = len(password) >= 86has_digit = any(char.isdigit() for char in password)78if has_length and has_digit:9 print("Password is valid")10else:11 print("Password is invalid")12 if not has_length:13 print("- Must be at least 8 characters")14 if not has_digit:15 print("- Must contain at least one digit")
Output
Enter password: password123 Password is valid Enter password: pass Password is invalid - Must be at least 8 characters - Must contain at least one digit
What's going on
Check multiple password requirements.
Key Concepts:
Check length >= 8
Check if contains digit using any()
Use AND to ensure both conditions
Provide specific error messages
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum