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

walter olazabal
walter olazabal
7,407 Points

NameError: name 'slice1' is not defined

NameError: name 'slice1' is not defined.

It gives me that oce I dont understand why. I did it perfect

walter olazabal
walter olazabal
7,407 Points

Let's get in some slice practice!

Create a new variable named slice1 that has the second, third, and fourth items from favorite_things.

favorite_things = ['raindrops on roses', 'whiskers on kittens', 'bright copper kettles', 'warm woolen mittens', 'bright paper packages tied up with string', 'cream colored ponies', 'crisp apple strudels'] slice1 = favorite_things[1:5]

1 Answer

Eric M
Eric M
11,545 Points

Hi Walter,

I think there's something a little wrong with the checking for this challenge. I've reported it.

Just a note though, you want slice1 = favorite_things[1:4] not 1:5. The requirement is for the second, third, and fourth items. The first item in the square brackets is inclusive (the index will be included in the slice) and the second item is exclusive (the index will not be included in the slice) and the index starts from 0. So your slice of [1:5] would have included the second, third, fourth, and fifth items in the original list as the fith item has an index of 4.

In the meantime you'll probably want to skip ahead to the next video and come back to this one when the issue's resolved. Looks like you've got the right idea about slice basics though :)

Cheers,

Eric