Number Meeting Multiple Conditions
Filter one through one hundred with three number rules in Python. Students combine shared divisibility, even digit sums, and exclusion of multiples of seven.
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 15 60 75
In this one
- Combine three filters
- Derive a digit property
- Reset candidate state
How it works
- 1
Visit one through one hundred.
- 2
Calculate divisibility, digit-sum parity, and seven-exclusion booleans.
- 3
Print candidates passing all three.
Edge cases
Does 15 print?
Does 15 print?
Yes. It passes all three requirements.
Does 30 print?
Does 30 print?
No. Its digit sum is three.
What's going on
Each candidate needs divisibility by both three and five, an even digit sum, and nondivisibility by seven. Separate booleans describe the rules.
For 15, the sum is six and the candidate qualifies. Thirty fails the even-sum rule. The final and chain requires all conditions, so satisfying the shared-multiple test alone is not enough. Candidate state is recalculated on every iteration.
Does 15 print? Yes. It passes all three requirements.
Does 30 print? No. Its digit sum is three.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which rule excludes a multiple of seven?
Pick an answer to check it.
Question 2
Does 15 print?
Pick an answer to check it.
Questions people ask
Does 15 print?
Yes. It passes all three requirements.
Does 30 print?
No. Its digit sum is three.
Which rule excludes a multiple of seven?
num % 7 != 0.
๐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