sum

Requirements:

  • loop with an accumulator variable

  • loop through a list (for)

  • returning a value

Please see starter code docstring for requirements.

Starter Code

from typing import List


def sum_list(numbers: List[float]) -> float:
    """Returns the sum of a list of numbers.

    Args:
        numbers: A list of float numbers.
    Returns:
        The sum of the numbers.
    
    Note: Do NOT use the sum() built-in function to 
          accomplish this. Use a loop.
    """
    return 0

Tests

from main import sum_list


def test_sum_list():
    assert sum_list([1.0, 1.0, 1.0]) == 3.0
    assert sum_list([1.5, 1.5, 1.5]) == 4.5
    assert sum_list([]) == 0
    assert sum_list([-10, 10]) == 0