Test Informed Learning with Examples

Logo

Repository with assignments using the Test Informed Learning with Examples (TILE) method to integrate testing into existing programming courses for free.

Menu

LinkedIN Community

Join our LinkedIN Community.

Calculating sums of the even- and the odd-indexed numbers

Write a odd_sum function that takes a list or tuple of numbers. It should return a two-element tuple, containing (respectively) the sum of the even-indexed numbers and the sum of the odd-numbered numbers. Example:

>>> odd_even_sum([2,4,6,1,12,3,4])
    (24, 8)
>>> odd_even_sum([0,2,4,6,1,12,3,4])
    (8, 24)
>>> odd_even_sum((1,2,1,2,1,2))
    (3, 6)
>>> odd_even_sum((2,1,2,1,2,1,2))
    (8, 3)
>>> odd_even_sum(())
    (0, 0)
>>> odd_even_sum([])
    (0, 0)