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 trialDarryn Smith
32,043 PointsCode 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?
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
Treehouse Moderator 68,441 PointsThere 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)
Ken Alger
Treehouse TeacherDarryn;
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
32,043 PointsThanks to both of you. Aiaiaiai, nothing like a space or semicolon to bring the day to a halt!
Cheers!
Lynn Collins
10,080 PointsI'm TOO SLOW!!! Mine keeps getting messed up! I hate these challenges!
Lynn Collins
10,080 PointsI'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)"""
Lynn Collins
10,080 PointsYou are all so much smarter that I will ever be. I'm crying hard right now.
Lynn Collins
10,080 PointsI give up even trying, seriously, what's the point
Lynn Collins
10,080 Pointsdef average(num_list): """Return the average for a list of numbers"""
return sum(num_list) / len(num_list)
I erased it all.
Bala Selvam
Python Development Techdegree Student 30,590 PointsBala Selvam
Python Development Techdegree Student 30,590 PointsDoes 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
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsEither 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.