write a python program to take n numbers as input and count the even numbers and print the output .
Answers
Answered by
1
Answer:
a=int(input("Enter number of numbers"))
count=0
for i in range(a):
n=int(input("Enter the number"))
if n%2==0:
count+=1
print(count)
Answered by
31
★
n = int(input("Enter the number of elements to be inserted: "))
temp = 0
num = []
for i in range(n):
num.append(int(input("Enter element {}: ".format(i+1))))
for nums in num:
if nums % 2 == 0:
temp += 1
print("Total even numbers: {}".format(temp))
★
- In this program, we first take an integer input n from the user, which represents the number of elements to be inserted. We then create an empty list num to store the input numbers.
- Next, we use a for loop to take n numbers as input from the user and append them to the num list.
- After that, we use another for loop to iterate through the num list and check if each element is even or not using the modulo operator (%). If an element is even, we increment the count variable.
- Finally, we print the total number of even numbers by formatting the count variable using the print() function.
Similar questions