Write a program to count and print the number of odd and even numbers

Write a program to count and print the number of odd and even numbers


This program is used to find the number of even and odd numbers within a certain limit. The limit is defined by the variable "l" which is taken as input from the user. The program then uses a for loop to iterate through the range of numbers defined by the limit. For each number, the program checks whether the number is even or odd by using the modulus operator (n%2). If the number is even, it is appended to the "even" list, and if the number is odd, it is appended to the "odd" list. After the for loop completes, the program prints the length of the "even" list and the "odd" list, which gives the number of even and odd numbers respectively within the given limit.

Source Code

l = int(input("Enter the Limit :"))
even=[]
odd=[]
for i in range(l):
	n = int(input("Enter the Values :"))
	if(n%2==0):
		even.append(n)
	else:
		odd.append(n)
print("Number of Even :",len(even))
print("Number of Odd :",len(odd))

Output

Enter the Limit :4
Enter the Values :12
Enter the Values :34
Enter the Values :23
Enter the Values :45
Number of Even : 2
Number of Odd : 2


Example Programs