Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

AdvancedPhase 6 - Category 1: Number LogicExample 2 of 10
number-meeting-multiple-conditions.py
1# Find numbers meeting conditions
2print("Numbers 1-100 that are:")
3print("- Divisible by 3 and 5")
4print("- Sum of digits is even")
5print("- Not divisible by 7")
6
7for num in range(1, 101):
8 div_3_5 = num % 3 == 0 and num % 5 == 0
9 digit_sum = sum(int(d) for d in str(num))
10 sum_even = digit_sum % 2 == 0
11 not_div_7 = num % 7 != 0
12
13 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. 1

    Visit one through one hundred.

  2. 2

    Calculate divisibility, digit-sum parity, and seven-exclusion booleans.

  3. 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.