Len's slice Trace Back error

Hey everyone! Ive been stuck on this checkpoint for a while now and Im not to sure how to fix this issue. Ill post my code here now so you all can see it:
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(len(toppings))

print("We sell " + str(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()

and here is a photo:

I found out what trace back error meant and i thought i made the 2d list correctly? Any help would be amazing I’m pretty stuck. Thanks, guys, and happy coding!

Double-check your pizza_and_prices variable. This should contain a list of sublists where each sublist contains two elements: the price and type of pizza.

The requirement is:

  1. Convert our toppings and prices lists into a two-dimensional list called pizza_and_prices that has the following associated values.

Instead, you’re doing this manually :thinking::

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

The result of task 6 should be:
[[2, 'pepperoni'], [6, 'pineapple'], [1, 'cheese'], [3, 'sausage'], [2, 'olives'], [7, 'anchovies'], [2, 'mushrooms']]

To give you a hint, it should be something like this:

pizza_and_prices = []
for i in range(len(prices)):
    pizza_and_prices.append( ?, ? )

thank you so much! I manged to finish the project, i just had one more question.

in this part: Since there is no longer an "anchovies" pizza, you want to add a new topping called "peppers" to keep your customers excited about new toppings.
Add the new peppers pizza topping to our list pizza_and_prices .

Note: Make sure to position it relative to the rest of the sorted data in pizza_and_prices , otherwise our data will not be correctly sorted anymore!

i manged to get peppers in the list in the right spot but it does not follow the same format as the following and past entries, I was wondering how to make it do so? here is a photo as well:

1 Like

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

1 Like