Help! Python 3: Working With Lists section - final exercise not working


I am working on the 4th step of the final exercise of the “Working with Lists” lesson on the Python 3 course.

I keep receiving an error and it is preventing me from progressing through the exercise. I believe that the error is with the exercise itself - particularly the values in the given list. This is because the list contains 19 items however in the 3rd step when I popped the value at index 18 it came back with an error saying that this index was out of range. I changed my code to pop the value at the index “-1” and it allowed me to move to the next step.

The 4th step asks me to “Select items from the inventory starting at index 2 and up to, but not including, index 6. Save your answer to a variable called inventory_2_6.” And I wrote - inventory_2_6 = inventory[2:6]. I received an error saying the value for inventory_2_6 did not match the expected value. And I double checked by going back to the previous exercises so I am sure the syntax is correct.
Here is the code for I have written and the error:

and here is the link to the exercise:

I appreciate any help that can be given :))

Here is the code without any obstruction

I think you misunderstood the instructions for items 2 & 3. You’re removing and returning those items from the list by using .pop()—thus altering the list itself—which is not what is asked.

What is asked is this: “Select the first element in inventorySelect the last element…”
Selecting items doesn’t remove them from the list, nor does it alter the list itself.

Which would be:

first = inventory[0]

last = inventory[-1]
1 Like

OMG yes! I misunderstood.
I just followed what you said and it worked.
Thank you so much! :))


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