Phase 4 - Level 2: Searching & Counting Logic
Master array searching, counting occurrences, and finding elements.
10 programs · open one, then the next
Start with Check if Element Exists- 01Check if Element ExistsIntermediateCheck whether an entered integer occurs in a list. Students use membership for a yes-or-no search and compare existence with finding a position or frequency.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 02Count OccurrencesIntermediateCount occurrences of a chosen integer in a Python list. Students use list.count and distinguish zero matches, repeated entries, and a single combined result.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 03Find First OccurrenceIntermediateFind the first occurrence of an integer in a list. Students guard list.index with membership and learn the difference between zero-based position and frequency.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 04Find Last OccurrenceIntermediateFind the last occurrence with a Python index scan. Students update a saved position on every match and use minus one only as a not-found sentinel.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 05Check UniquenessIntermediateCheck whether every list element is unique. Students compare list length with set size and understand how repeated values disappear during set conversion.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 06Sum of Even ElementsIntermediateSum even-valued entries in a list. Students filter by a value's remainder and keep repeated contributions instead of counting matches or selecting even indexes.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 07Sum of Odd ElementsIntermediateAdd odd-valued entries from a list with a remainder filter. Students distinguish summing values from counting them and include negative odd integers honestly.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 08Count Prime NumbersIntermediateCount prime entries in a list using a helper function. Students numeric classification from traversal and understand why repeated primes count repeatedly.Open example →py# Helper function def is_prime(num): if num < 2: return False
- 09Count Divisible by 3 & 5IntermediateCount list values divisible by both three and five using Python. Students combine two remainder conditions and include every matching occurrence in the counter.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 10Count Perfect SquaresIntermediateCount perfect-square entries in a list. Students reject negatives, verify an integer candidate root, and recognize the limits of floating-point square roots.Open example →py# Helper function def is_perfect_square(num): if num < 0: return False