Python

walter olazabal
walter olazabal
2,934 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
2,934 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 McKibbin
MOD
Eric McKibbin
Treehouse Moderator 10,976 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