CJCoding With Joseph
15free / daySign inCreate account

Count Even Numbers

Write count_evens(values: list[int]) -> int that returns how many even numbers the list holds, by recursion: an empty list holds none; otherwise test the first value with the remainder operator % and add 1 to the count for the rest of the list (the slice values[1:]) when it is even, or return the count for the rest unchanged when it is odd. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of integers separated by spaces (it may be empty), which the tests read into a list and pass to your function before printing the value it returns.

Expected Output:

3

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
RecursionOperatorsSlicing
📥 Auto-Input:
1 2 3 4 6\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.