University of Arizona, Department of Computer Science

CSc 120: Sum the Odd Numbers (Recursive)

Expected Behavior

Write a recursive function sum_odds(arglist), where arglist is a list of integers, that returns the sum of all of the odd elements of arglist.

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. sum_odds([1,3,5,7,6])
    return value: 16

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

  3. sum_odds([])
    return value: 0

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