# Len's Slice

Hello, i am stuck on this excersize:

Len’s Slice

I have read several other forum posts and copied the code to a T but i still get this error code:

""Traceback (most recent call last):
File “script.py”, line 21, in
pizza_and_prices.insert(3, 2.5, “peppers”)
TypeError: insert() takes exactly 2 arguments (3 given)

This is my code:

``````toppings = ["pepperoni", "pineapple", "cheese", "sausage", "olives", "anchovies", "mushrooms"]

prices = [2, 6, 1, 3, 2, 7, 2]

num_two_dollar_slices = prices.count(2)

print(num_two_dollar_slices)

num_pizzas = len(toppings)

print("We sell " , num_pizzas, " different kinds of pizza!")

pizza_and_prices = [[2, "pepperoni"], [6, "pineapple"], [1, "cheese"], [3, "sausage"], [2, "olives"], [7, "anchovies"], [2, "mushrooms"]]

#print(pizza_and_prices)

pizza_and_prices.sort()

cheapest_pizza = pizza_and_prices[0]

priciest_pizza = pizza_and_prices[-1]

#print(priciest_pizza)

pizza_and_prices.pop()

print(pizza_and_prices)

pizza_and_prices.insert(3, 2.5, "peppers")

#print(pizza_and_prices)
``````

I have commented out the parts that i don’t have use for at this moment to help me focus easier. Thanks in advance.

I think i solved it, not the way some others might’ve though. This might be useful to others so i will just write it here anyways:

I swapped:
`pizza_and_prices.insert(3, 2.5, "peppers")`

for:

`pizza_and_prices[3] = [2.5, "peppers"]`

And it worked. Very good.

You have an error here:

`print("We sell " , num_pizzas, " different kinds of pizza!")`

``````
print('We sell ' + str(num_pizzas) + " different kinds of pizza!")
``````

and, as the error message says, here:

`pizza_and_prices.insert(3, 2.5, "peppers")`

You used `.insert()` incorrectly. As the error message says, “TypeError: insert() takes exactly 2 arguments (3 given)”, it takes two arguments, but the item you want to insert is a list, and that needs brackets.

Like:

``````pizza_and_prices.insert(4, [2.5, "peppers"])
``````

See:

2 Likes

` print('We sell ' + str(num_pizzas) + " different kinds of pizza!")`
Ah i didn’t notice.

`pizza_and_prices.insert(4, [2.5, "peppers"])`
I did try that, i think i wrote a 3 instead of a 4 though. I might have used a incorrect symbol somewhere. I copied the code and it works as it should now, thanks a lot!

1 Like