Count Divisible by 3 & 5
Count elements divisible by both 3 and 5.
IntermediatePhase 4 - Level 2: Searching & Counting LogicExample 9 of 10
count-divisible-by-3-5.py
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
What's going on
Check both conditions with AND.
Key Concepts:
Divisible by 3: element % 3 == 0
Divisible by 5: element % 5 == 0
Both must be true
🔗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