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 trialVictor Gavojdea
11,796 PointsDoctest code works in python but not on the test.
when I go into python on a separate window and run the test code it works and returns 1.5 like it should. Why am I not getting it right on the test?
def average(num_list):
"""Return the average for a list of numbers
>>>list = [1, 2]
>>>average(list)
1.5
"""
return sum(num_list) / len(num_list)
3 Answers
Steven Parker
231,184 PointsI guess the challenge is pickier than the Python itself.
The challenge wants your test to call the function by passing the test list as a literal and not use an intermediate variable.
The challenge also wants to see a space between the chevrons (>>>) and the function call.
SPOILER ALERT
def average(num_list):
"""Return the average for a list of numbers
>>> average([1, 2])
1.5
"""
return sum(num_list) / len(num_list)
</div>
Victor Gavojdea
11,796 PointsSlightly annoying, but thank you.
bezruki
6,532 PointsSteven, thanks for the answer. I had this:
def average(num_list):
"""Return the average for a list of numbers
>>> av = average([1, 2])
>>> av == 1.5
True
"""
return sum(num_list) / len(num_list)
which also didn't work - grad my answer wasn't too off
Thomas Helms
16,816 PointsThomas Helms
16,816 PointsYep, I had
and it was giving me fits. I knew I wasn't that far off. Thanks Steven.