Count Numbers Divisible by 7 but Not 5
Count numbers 1-500 divisible by 7 but not 5.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 2 of 12
count-numbers-divisible-by-7-but-not-5.py
1# Count numbers2count = 03for num in range(1, 501):4 if num % 7 == 0 and num % 5 != 0:5 count += 167print(f"Count: {count}")
Output
Count: 57
What's going on
Check both conditions with AND.
Key Concepts:
Divisible by 7: num % 7 == 0
Not divisible by 5: num % 5 != 0
Count matching numbers
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum