# Is this code is correct for len slice

toppings=[“pepperoni”,“pineapple”,“cheese”,“sausage”,“olives”,“anchovies”,“mushroom”]

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” + 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()

cheapest_pizza=pizza_and_prices[0][1]

pizza_and_prices.pop(-1)

pizza_and_prices.insert(4, [2.5, “peppers”])

three_cheapest=pizza_and_prices[2:]

print(three_cheapest)

1 Like

Does it produce the intended results? Do you get any errors? Or, do you have a more specific question about the project?

1 Like

not get errors, but im confused as I write the correct code.

What part confuses you?

I was stocked with
pizza_and_prices.insert(4, [2.5,“peppers”])
you really help me

toppings = [“pepperoni”, “pineapple”, “cheese”, “sausage”, “olives”, “anchovies”, “mushrooms”]
prices = [2, 6, 1, 3, 2, 7, 2]
num_two_dollar_slices = prices.count(2)
num_pizzas = len(toppings)

# print(“We sell”, num_pizzas, “different kinds of pizza!”)

pizza_and_prices = [[2, “pepperoni”], [6, “pineapple”], [1, “cheese”], [3, “sausage”], [3, “olives”], [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]
pizza_and_prices.pop()
pizza_and_prices.insert(4, [2.5,“peppers”])
#chouse 3 lowest cost pizzas
three_cheapest = pizza_and_prices [0:3]

print(pizza_and_prices)
print(cheapest_pizza)
print(priciest_pizza)
print(three_cheapest)

I thing you are wrong with
three_cheapes

my suggestion:
three_cheapest = pizza_and_prices [0:3]
or
three_cheapest = pizza_and_prices [:3]

1 Like