In this article, we will show you, How to write a Python Program to Count Even and Odd Numbers in an Array using For Loop.
1 2 3 4 5 6 7 8 9 10 11 12 | a=0 b=0 arr = [1,5,6,9,6,8] for i in range(0,len(arr)): if(i%2==0): #even numbers a+=1 else: b+=1 print('There are {0} numbers that are even'.format(a)) print('There are {0} numbers that are odd'.format(b)) |
Output: