# Python Program to Count Even and Odd Numbers in a List

This article is created to cover some programs in Python that count the total number of even and odd numbers available in a given list entered by the user at run-time. Here is a list of programs covered in this article:

• Count even or odd numbers in a list of 10 elements.
• Count even or odd numbers in a list of n elements.

## Count Even or Odd in a List of 10 Elements

The question is: write a Python program to count the total number of even and odd numbers present in a list of 10 numbers entered by the user. Here is its answer:

```nums = []
totEven = 0
totOdd = 0

print("Enter 10 Numbers: ")
for i in range(10):
nums.insert(i, int(input()))

for i in range(10):
if nums[i]%2==0:
totEven = totEven+1
else:
totOdd = totOdd+1

print("\nEven Number: ")
print(totEven)
print("Odd Number: ")
print(totOdd)```

Here is its sample run:

Now supply the input as any 10 numbers, say "1, 2, 3, 4, 5, 6, 7, 8, 9, 10," and then press the ENTER key to count and print how many even and odd numbers are available in the given list, as shown in the snapshot given below:

## Count even or odd numbers in a list of n elements

This program allows the user to define the size of the list. The question is: write a Python program to count even or odd numbers in a list of size n. The following program is the answer to this question:

```nums = []
totEven = 0
totOdd = 0

print(end="Enter the Size: ")
size = int(input())

print(end="Enter " +str(size)+ " Numbers: ")
for i in range(size):
nums.insert(i, int(input()))

for i in range(size):
if nums[i]%2==0:
totEven = totEven+1
else:
totOdd = totOdd+1

print("\nEven Number: " +str(totEven))
print("Odd Number: " +str(totOdd))```

Here is its sample run with user input "5" as size and "1, 2, 3, 4, 5" as five numbers:

Python Online Test

« Previous Program Next Program »

Liked this post? Share it!