Final answer:
To count the number of even and odd numbers in a list, you can use a for loop and the modulo operator. Initialize two variables to keep track of the counts, then iterate over each number in the list and check if it is even or odd. Increment the corresponding count variable based on the result.
Step-by-step explanation:
To count the number of even and odd numbers in a list, you can use a for loop. Here is an example:
numbers = [1, 2, 3, 4, 5, 6] # Replace with your list
count_even = 0
count_odd = 0
for num in numbers:
if num % 2 == 0: # Check if number is even
count_even += 1
else:
count_odd += 1
print('Number of even numbers:', count_even)
print('Number of odd numbers:', count_odd)
In this example, we have a list called 'numbers' which contains the numbers you want to count. The 'count_even' and 'count_odd' variables are initialized to 0. The for loop iterates over each number in the list and checks if it is even or odd using the modulo operator (%). If the number is even, the 'count_even' variable is incremented by 1. If the number is odd, the 'count_odd' variable is incremented by 1. Finally, we print the counts of even and odd numbers.