Count the even numbers

Read a list of whole numbers and print how many of them are even.

What to build

A loop with a decision inside it.

Requirements

  • Read the list of numbers.
  • Count those that divide evenly by 2.

Input

The first line has n (1 to 1000). The second line has n whole numbers separated by spaces.

Output

How many of the numbers are even.

Constraints

n is from 1 to 1000.

Example

Input:

5
1 2 3 4 6

Output:

3

Why it works

The counter goes up only when the test passes, so at the end it holds exactly how many numbers passed.

Examples

Example 1 · Input
5
1 2 3 4 6
Expected output
3
Example 2 · Input
3
1 3 5
Expected output
0

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

"1 2 3".split() gives ["1", "2", "3"]: text, not numbers.

Hint 2

A number x is even when x % 2 == 0.

Solution

Show one correct solution (try it yourself first)
n = int(input())
parts = input().split()
count = 0
for part in parts:
    if int(part) % 2 == 0:
        count += 1
print(count)

Lesson: Repeating with for loops →