Write a program that takes an array of integers as input. Find and print the count of even numbers in the array.
from array import array
# Function to count even numbers in an array
def count_even_numbers(input_array):
count = 0
for num in input_array:
if num % 2 == 0:
count += 1
return count
# Take an array of integers as input
input_array = array('i', [int(x) for x in input("Enter space-separated integers: ").split()])
# Find and print the count of even numbers
even_count = count_even_numbers(input_array)
print(f"The count of even numbers in the array is: {even_count}")
In this program:
The user is prompted to enter space-separated integers, and the input is converted into an array of integers.
The function count_even_numbers iterates through the array and increments the count for each even number.
The count of even numbers is printed.
You can input integers separated by spaces, and the program will output the count of even numbers in the array.
Inter Board Karachi Guess/Model Papers 2023 Board Karachi Model Papers 2023 Computer's Guess Paper 9th Class 2023 Computer's Guess Paper 9th Class 2026 Computer's Guess Paper 10th Class 2023 Computer's Guess Paper 11th Class 2023 Computer's Guess Paper 12th Class 2023 Prepared By Sir Rana Arsalan Inter Part-I Model Papers Inter Part-II Model Papers Model Paper Mathematics I Model Paper Mathematics II Model Paper Islamiat Model Paper Urdu II Model Paper Urdu I Model Paper Pakistan Studies Model Paper Botany I Model Paper Botany II Model Paper Chem I — MCQs Model Paper Chem II — MCQs Model Paper Physics I Model Paper Physics II Model Paper Zoology I Model Paper Zoology II Model Paper English I Model Paper English II
Comments
Post a Comment
If you have any doubts, Please let me know .