University of Arizona, Department of Computer Science

CSc 120: Count the Odd Elements (Recursion)

Expected Behavior

Write a recursive function count_odds(arglist), where arglist is a list of integers, that returns the number of elements in arglist that are odd.

Programming Requirements

Solve this problem using recursion. You are allowed to use only the following programming constructs:

Solutions that go outside these constructs, e.g., by using for/while loops or list comprehensions, will not get credit.

Examples

  1. count_odds([1,3,5,7,6])
    return value: 4

  2. count_odds([2,4,6])
    return value: 0

  3. count_odds([])
    return value: 0

  4. count_odds([1,2,3,4,5,6,7,8,9])
    return value: 5