I'm not sure what I'm doing wrong?


#1

When I write two index numbers of a string the computer only seems to detect one?
middle = suitcase[2:3]

When I imput this it says that I only put in 2 when 3 is the other answer.

It should slice out those two pieces from the list but it says that only one is there. It gives me this error:
"Oops, try again. It looks like your middle slice is ["passport"] instead of ["passport", "laptop"]. "
Passport and laptop are numbers two and three in the list, that I know, so what is going on?


Replace this line with your code.


#2

the slice has two values:

[start:stop]

you use 2 as start value, and 3 as stop value. However, for the values goes that it are indexes lesser then (<) the stop value, not lesser then or equal to the stop value (<=)


#3

I'm sorry I don't really understand. The lesson "List Slicing" says that I need to just put the indexes for the middles two strings in the list. There are five total and the indexes two and three are the middle ones. When I put those in where the lesson tells me to, it literally tells me to put two and three in like so, [2:3], it just keep telling me that I only put 2 in.


#4

but if you do, [2:3] the stop value (3) is not included, because for list slicing, it is values lesser then 3. you also need to include index 3, so you need 4 as stop value


#5

3 posts were split to a new topic: Slicing


#6

Oh okay think I understand. Thank you.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.