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

Darryn Smith
Darryn Smith
32,043 Points

Code not passing Challenge: Create a Doctest. Help, please.

I've been over and over this code and can't figure out why I'm not passing the challenge.

The assignment is: "Add a doctest to average() that tests the function with the list [1, 2]. Because of how we test doctests, you'll need to leave a blank line at the end of your doctest before the closing quotes."

What am I not getting?

average.py
def average(num_list):
    '''Return the average for a list of numbers

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

    '''
    return sum(num_list) / len(num_list)

8 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

There is a space needed between the >>> prompt and the statement:

def average(num_list):
    '''Return the average for a list of numbers

    >>> average([1, 2])  # <-- added space after prompt
    1.5

    '''
    return sum(num_list) / len(num_list)
Bala Selvam
seal-mask
.a{fill-rule:evenodd;}techdegree
Bala Selvam
Python Development Techdegree Student 30,590 Points

Does it matter if you put in a """ or a ''', because for some reason i put everything the same in the challenge but those and when i switched out the """ for the ''' it passed

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Either triple-single-quotes or triple-double-quotes should work equally as well. I test the posted answer with both styles and it passes. Perhaps some other typo was introduced.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Darryn;

You are missing a space between your >>> and your average statement. Add that space in there and your code works fine.

Happy coding,
Ken

Darryn Smith
Darryn Smith
32,043 Points

Thanks to both of you. Aiaiaiai, nothing like a space or semicolon to bring the day to a halt!

Cheers!

I'm TOO SLOW!!! Mine keeps getting messed up! I hate these challenges!

I'm not very bright...... def average(num_list): """Return the average for a list of numbers"""

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

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

You are all so much smarter that I will ever be. I'm crying hard right now.

I give up even trying, seriously, what's the point

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

return sum(num_list) / len(num_list)

I erased it all.