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.
1# Take array2n = int(input("Enter array size: "))3arr = []4for i in range(n):5 arr.append(int(input(f"Element {i+1}: ")))67# Count8count = 09for element in arr:10 if element % 3 == 0 and element % 5 == 0:11 count += 11213print(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
Start count at zero.
- 2
Require remainder zero for both three and five.
- 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.
๐Related Content
- ๐
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- ๐
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- ๐ป
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum