In this program, we will count the number of even and odd numbers from a series of numbers.
Steps to solve the program
- Take a series of numbers as input.
- Create two variables even and odd and assign their value equal to 0.
- Use for loop to iterate over each number from the series.
- If the number is even add 1 to the even and if the number is odd add 1 to the odd.
- 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