Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Testing First Steps With Testing Create a Doctest

bummer check preview for details , I have space in between , but it is still not working what am i doing worn

need help answer is almost right

average.py
def average(num_list):
    """ Return the sum of a list of numbers    

    >>> average([1, 2])
    1.5    

    """
    return sum(num_list)

3 Answers

It's asking for an average. You're half way there.

  • You'll need to use the len() function on num_list to return the length of the list.

  • Then divide sum(num_list) by len(num_list).

def average(num_list):
    """ Return the sum of a list of numbers    

    >>> average([1, 2])
    1.5    

    """
    return sum(num_list) / len(num_list)

thank you so much that worked, NOTE: had to delete all empty space lines and then add the spacing in the lines in between average and after the 1.5 and it finally worked.

Note after numbers hit enter and after 1.5 hit enter must have a line of space

def average(num_list): """ Return the sum of a list of numbers >>> average([1, 2]) 1.5
""" return sum(num_list) / len(num_list)

That's weird but I'm glad you got it working, Cheers!