Python program to count numbers of even and odd elements in an array
Login/Signup to comment
6 comments on “Python program to count numbers of even and odd elements in an array”
×


30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
arr = [1, 7, 8, 4, 5, 16, 8]
ev = od = 0
for i in range(0,len(arr)):
if arr[i]%2==0:
ev+=1
else:
od+=1
print(f”Evens are {ev} and odds are {od}.”)
array=list(map(int,input(“Enter a array”).split()))
counteven=0
countodd=0
for i in array:
if i%2==0:
counteven+=i
else:
countodd+=i
print(f”Even:{counteven}”)
print(f”odd:{countodd}”)
num = input().split(‘,’)
ls=[int(item) for item in num]
even=0
odd=0
even_nums=[]
odd_nums=[]
for i in range(len(ls)):
if ls[i]%10==0:
even+=1
even_nums.append(str(ls[i]))
else:
odd+=1
odd_nums.append(str(ls[i]))
even_n=’ ‘.join(even_nums)
odd_n=’ ‘.join(odd_nums)
print(f”Even Elements count={even}({even_n})”)
print(f”Even Elements count={odd}({odd_n})”)
a=[1, 7, 8, 4, 5, 16, 8]
even_count=0
odd_count=0
for i in a:
if i%2==0:
even_count+=1
else:
odd_count+=1
print(even_count)
print(odd_count)
a = [1, 7, 8, 4, 5, 16, 8]
c=0
p=0
for i in a:
if(i%2==0):
c+=1
else:
p+=1
print(“even =”,c ,”odd =”, p)
arr = [1, 2, 6, 3, 7]
n = len(arr)
def f(arr,n):
even , odd = 0,0
for i in arr:
if(i % 2 == 0):
even += 1
else:
odd += 1
print(even , odd)
f(arr,n)