Logic Building
# Take array
n = int(input("Enter array size: "))
arr = []
for i in range(n):
arr.append(int(input(f"Element {i+1}: ")))
# Count
even = 0
odd = 0
for element in arr:
if element % 2 == 0:
even += 1
else:
odd += 1
print(f"Even: {even}, Odd: {odd}")Output
Enter array size: 5 Element 1: 2 Element 2: 3 Element 3: 4 Element 4: 5 Element 5: 6 Even: 3, Odd: 2
Check each element for even/odd.
Key Concepts:
- Use modulo to check even/odd
- Increment respective counter
- Print counts