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 trialPhillip Bailey
1,822 PointsReturn first 4 words from any iterable
def first_4(word): print(word[:4]) return word
first_4("apple")
If you run this on the string "apple" it returns the "appl" so I'm confused why its not correct. Also the return statement at the end if left alone returns a blank program and seems if nothing was ran. I did call the function as well.
def first_4(word):
print(word[:4])
return word
2 Answers
Cheo R
37,150 PointsYou're on the right track.The way you have it now is that your function will print the first 4 letter in the word, and returns the word itself. What you want to do is return the first 4 letters in the word. So just combine them to return the first 4 letters.
Moderator Edit: moved response to Answer section
Phillip Bailey
1,822 PointsThank you for that, I see what I did wrong there now :) I am just stuck now on step 3/4 returning the odd values. I'm very close though.
Cheo R
37,150 PointsKey part is:
- odd index*
If you remember, lists/strings in python are 0-based. So the indexes of a list of length 4 would be 0, 1, 2, 3. You want to return the values when the index is an odd number (i.e. value of index 1, 3).