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 trial

Python Python Collections (2016, retired 2019) Slices Slice Functions

horus93
horus93
4,333 Points

Did I misread the question?

So the challenge task states

Alright, these tasks are a bit harder than the others so far in this course but I know you can do them!

In this first one, create a function named first_4 that returns the first four items from whatever iterable is given to it.

And with the code I wrote, the program asks for your input, and returns the first 4 places of whatever iterable you put in, which I thought was what they were asking me, but also I remember in a previous challenge I got into trouble with the challenge engine by requiring user input which screwed it up (even though it seemed to be asking for it here). Did I just need to give it a static value? Or did I misread the challenge and do things wrong?

slices.py
def first_4():
    question = input("What would you like to get the first 4 from?\n>")
    gimmie = question[0:4]
    print (gimmie)

while True:
    first_4()

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

This challenge isn't asking you to ask the user for input. Instead, the value you'll be operating on will be passed into your function as a parameter. Note that you'll also be returning that value instead of printing it