Python 3: Len's Slices - Tuple Step 7: Tuple Error

Your code below:

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”], [2, “olives”], [7, “anchovies”], [2, “mushrooms”]]

print(pizza_and_prices)

This is the code that I have written so far. Step 7 asks that pizza_and_prices be printed out. Running the above code throws a TypeError: ‘tuple’ object is not callable. Any advice because this is driving me crazy.

Riley

This isn’t right.
print = ("We sell “, num_pizzas, " different kinds of pizza!”)

Because of the = , the above is interpreted as assigning a tuple to print. In Python 2, print was a reserved keyword, so the above statement would have caused an error. But in Python 3, print is no longer a reserved keyword and is instead a built-in function.
Since print isn’t reserved, your statement assigns a tuple to print.
Later when you try to make the call
print(pizza_and_prices)
you get the error: TypeError: 'tuple' object is not callable

Oh my gosh…I didn’t even notice that I had set up the print statement like that. Taking it out fixed the error. Thank you!

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