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 trialreza sajadian
718 PointsI cant solve this quiz: Make a function named first_4 that accepts an iterable as an argument and returns the first 4 i
I dont understand why my code doesnt work for this quiz:
Make a function named first_4 that accepts an iterable as an argument and returns the first 4 items in the iterable.
I guess you have my code attached. thanks guys.
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Reza. Welcome to Treehouse.
Like Brendan said, the "Attach Code" isn't currently functioning, but we can break down the first part of the challenge (it's only two lines). First you need to create (def) a function that takes one arguement (can be named anything). Second return just the first 4 'parts' of the argument. If a string was passed in, it will return the first 4 letter; If a list was passed in, it would return the first 4 items; etc.
def first_4(item): #creates the function with one argument called 'item'
return item[:4] #returns the first 4 of the value passed into 'item'
Hope that helps. Keep Coding! :)
reza sajadian
718 PointsThanks Jason. I had made it much more complicated! Great!
Jason Anders
Treehouse Moderator 145,860 PointsYou're welcome. And, I've done that so many times, even though simple usually works best. lol.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsThe 'attach code' thing is buggy and not working. Can you edit and post your code? (Also...you might want to google 'list slicing')