Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


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


This example shows, how to count the even and odd numbers in a given list. For loop iterate over the each element verify to check even numbers ,num%2 == 0 condition true then increase the even count else increase odd count in this program.

Example.py
a = [13,8,49,65,22,86,96,33,75]

even = 0
odd = 0 

for num in a:
    if num % 2 == 0:
        even += 1
    else:
        odd += 1
        
print("Even numbers in the list: ", even)
print("Odd numbers in the list: ", odd)

Output

Even numbers in the list:  4
Odd numbers in the list:  5

Prev Next