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 trialAman Kumaran
2,314 Pointscan someone tell me whats wrong with this code?
i know the code is wrong but still
def first_4(iterable):
iterable=[1,2,3,4,5]
iterable[:4]
return iterable
3 Answers
Ricky Catron
13,023 PointsWell first your last two lines are not indented so they are not within the function.
def test():
#i am in the function
#i am not
Your slice will return the first four elements but you are not doing anything with that. You should save it to a variable or simply return it.
def first_4(iterable):
iterable=[1,2,3,4,5]
first_4_items = iterable[:4]
return first_4_items
Goodluck! --Ricky
Calistus Oledibe
176 PointsCorrect the identation(s). i.e the last two lines must start at the same line as "iterable=[1,2,3,4,5]" .
Aman Kumaran
2,314 PointsGot it now, thanks :)