Number Meeting Multiple Conditions
Find numbers 1-100 meeting specific conditions.
AdvancedPhase 6 - Category 1: Number LogicExample 2 of 10
number-meeting-multiple-conditions.py
1# Find numbers meeting conditions2print("Numbers 1-100 that are:")3print("- Divisible by 3 and 5")4print("- Sum of digits is even")5print("- Not divisible by 7")67for num in range(1, 101):8 div_3_5 = num % 3 == 0 and num % 5 == 09 digit_sum = sum(int(d) for d in str(num))10 sum_even = digit_sum % 2 == 011 not_div_7 = num % 7 != 01213 if div_3_5 and sum_even and not_div_7:14 print(num, end=" ")15print()
Output
Numbers 1-100 that are: - Divisible by 3 and 5 - Sum of digits is even - Not divisible by 7 30 60 90
What's going on
Combine multiple conditions with AND.
Key Concepts:
Check divisibility conditions
Calculate digit sum
Combine all conditions
Filter numbers
🔗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