Please see the screenshot below. I get this error message, but what should I do about the float?
This is the link to the exercise: https://www.codecademy.com/paths/computer-science/tracks/cspath-cs-101/modules/cspath-python-lists/projects/python-lens-slice
Haven’t checked or anything but, at a first glance, I’d say that it needs an index and should should be a list, so like
.insert(4, [2.5, "peppers"]) because you’re meant to be adding a list (as shown in the instructions - note the brackets), not a float and a string, and there’s the note about positioning to determine which index.
Of course, I’ve not actually done this, so I may be totally wrong, but that’s what it looks like.
You get this error because the .insert() method takes the arguments in the following order
As you’d expect, the index must be an int and in your case a float is being passed. To fix your code, try this:
pizza_and_prices.insert(0, [2.5, 'anchovies'])
Doing so, will add the element [2.5m ‘anchovies’] in the beginning of your list.