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

Count Divisible by 3 & 5

Count list values divisible by both three and five using Python. Students combine two remainder conditions and include every matching occurrence in the counter.

IntermediatePhase 4 - Level 2: Searching & Counting LogicExample 9 of 10
count-divisible-by-3-5.py
1# Take array
2n = int(input("Enter array size: "))
3arr = []
4for i in range(n):
5 arr.append(int(input(f"Element {i+1}: ")))
6
7# Count
8count = 0
9for element in arr:
10 if element % 3 == 0 and element % 5 == 0:
11 count += 1
12
13print(f"Count: {count}")

Output

Enter array size: 5
Element 1: 15
Element 2: 30
Element 3: 10
Element 4: 20
Element 5: 45
Count: 3

In this one

  • Combine divisibility tests
  • Count matching positions
  • Include zero multiples

How it works

  1. 1

    Start count at zero.

  2. 2

    Require remainder zero for both three and five.

  3. 3

    Increment per matching entry and print count.

Edge cases

Does zero qualify?

Does zero qualify?

Yes. Both remainders are zero.

Does six qualify?

Does six qualify?

No. It is not divisible by five.

What's going on

Each element must satisfy both tests, joined by and. Equivalently, an integer must be a multiple of fifteen to qualify.

The counter increases by one, not by the element's value. Zero and negative multiples can pass because remainder zero still means exact divisibility. An empty list naturally reports zero without any special branch.

Does zero qualify? Yes. Both remainders are zero.

Does six qualify? No. It is not divisible by five.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which connection is used?

Pick an answer to check it.

Question 2

Does zero qualify?

Pick an answer to check it.

Questions people ask

Does zero qualify?

Yes. Both remainders are zero.

Does six qualify?

No. It is not divisible by five.

Which connection is used?

and.