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 trialAnthony Ruvinov
Courses Plus Student 7,638 PointsPlease help i dont know what to do
Can someone please help me figure out what's wrong?
def first_4(1, 2, 3, 4):
return first_4[:4]
2 Answers
Alexander Davison
65,469 PointsIt seems that you still aren't exactly familiar with defining functions. When defining a function, you should have the parameters in the parentheses, not the arguments themselves (the purpose of a function is to provide it different arguments at different times). Try:
def first_4(iterable):
return iterable[:4]
Grigorij Schleifer
10,365 PointsHi Anthony, the method's parameter should be a variable that is iterable. I just call it iterable or whatever works for you. Your slice specification is absolutely correct, but you should slice the parameter (iterable) that you provide to the method.
Look at this:
# iterable is the parameter that the first_4 function expects
def first_4(iterable):
# slice the parameter and return it
return iterable[:4]
Does it make sense?
Anthony Ruvinov
Courses Plus Student 7,638 PointsYa i get it now. Thanks a lot for the help!
Grigorij Schleifer
10,365 PointsYou are very welcome, Anthony.
Anthony Ruvinov
Courses Plus Student 7,638 PointsAnthony Ruvinov
Courses Plus Student 7,638 PointsOooh, Thanks i was just a bit mixed up with what it was asking me. Thanks for the help!
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo problem :)