Write a Python program that takes an array of six elements and prints the count of even and odd numbers present.
1Times asked
Jul 2026Last seen
Jul 2026First seen
💡 Model Answer
The task is to iterate through the list, check each element’s parity, and maintain two counters. A simple approach uses a for‑loop and the modulo operator. After the loop, print the two counts. Complexity is O(n) time and O(1) space.
python
# Example list of six elements
arr = [1, 2, 3, 4, 5, 6]
even_count = 0
odd_count = 0
for num in arr:
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
print(f"Even numbers: {even_count}")
print(f"Odd numbers: {odd_count}")If the array is provided by the user, you can read it with input() and split():
python
arr = list(map(int, input("Enter six integers separated by spaces: ").split()))This solution handles any six integers, correctly counts evens and odds, and outputs the results in a clear format.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500