Count the number of even and odd numbers

In this program, we will count the number of even and odd numbers from a series of numbers.

Steps to solve the program
  1. Take a series of numbers as input.
  2. Create two variables even and odd and assign their value equal to 0.
  3. Use for loop to iterate over each number from the series.
  4. If the number is even add 1 to the even and if the number is odd add 1 to the odd.
  5. Print the output.
				
					numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
even = 0
odd = 0

for val in numbers:
    if val%2 == 0:
        even += 1
    else:
        odd += 1
        
print("Number of even numbers: ",even)
print("Number of odd numbers: ",odd)
				
			

Output :

				
					Number of even numbers:  4
Number of odd numbers:  5
				
			

add the word from the user to the empty string

prints all the numbers from 0 to 6 except 3 and 6

Leave a Comment