← Back to Recursion
Question 607
Count Even Numbers
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
Sign in to use hintsTopics:
RecursionOperatorsSlicing
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.