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 trialmark zuckerberg
385 Pointsnot working
Why ?
def first_4:
a = list(range(20))
items = a[:4]
return items
first_4()
4 Answers
Steven Parker
231,236 PointsYour slice is good.
But your function needs to take in "a" as a passed argument instead of creating it yourself using range. Just fix that and you'll pass.
Also, you only need to define the function, not call it.
Robert Young
1,391 PointsExplicit answer redacted by moderator
Jennifer Nordell
Treehouse TeacherHi, Robert! I've removed the content of your answer as no explanation for how or why the code works was provided. Feel free to resubmit your answer with an explanation. This will provide the original poster with a better learning experience. Thanks!
Robert Young
1,391 PointsIt worked
Jennifer Nordell
Treehouse TeacherHi there! Just because it passes a challenge does not mean that the code is necessarily correct. The opposite is also true. Fully functional code may not pass a challenge because it doesn't meet a specific requirement. The challenge does not require a loop, and Steven is correct. Once a return statement is hit, the function exits meaning that it will only ever do one iteration. Also, in your code, you have (by necessity for a for loop) a variable named iterables
which is never used other than to start the iteration.
Treehouse does discourage the posting of an explicit answer without any explanation as to how or why the code works. Could you please update your answer to include an explanation? Thanks!
Ted Runyon
1,773 PointsAlso don't forget to add () when defining a function! def first_4():
Steven Parker
231,236 PointsThat would be part of having it "take in "a" as a passed argument".