Python Array Solution Q7

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.

Comments

Popular posts from this blog

Class X Test / Model Paper Chapter No 1 Computer

Inter Board Karachi Guess/Model Papers 2023 (1st year & 2nd year)

Dulla Bhatti Real Hero Of Muslims Rajput