Len’s Slice

just wondering how I would right this code
Print the string We sell [num_pizzas] different kinds of pizza! , where [num_pizzas] represents the value of our variable num_pizzas .

You could use + or you could use string formatting.

print("We sell " + num_pizzas + " different kinds of pizza!")
# using .format
print("We sell {} different kinds of pizza!".format(num_pizzas) )
# using f-string
print(f"We sell {num_pizzas} different kinds of pizza!")
# using %
print("We sell %s different kinds of pizza!" % num_pizzas)  # %s is for string
# in Python 3, you could also do 
print("We sell", num_pizzas, "different kinds of pizza!")
1 Like

do you think this would work or not
num_pizza=“We sell[num_pizzas]different kinds of pizza”

@janbazant1107978602 has given you 5 ways that will work. If you want to know if what you have proposed will work, try it, and find out.

1 Like

already did my bad on asking the question

No harm done. Trying things to see if they work can be a valuable learning experience.

almost finished the project completely second last one ive tried it just wondering why it won’t go through


Traceback (most recent call last):
File “script.py”, line 17, in
TypeError: integer argument expected, got float
what I wrote should be correct its not thats the error

The instructions say to insert the list [2.5, "peppers"] as an element of the list at the appropriate position so that everything is still sorted by price. So you are inserting it so that its index would be 4.
The first argument of .insert is the index where you want to insert stuff, the second is what you’re inserting into the list.

pizza_and_prices.insert(4, [2.5, "peppers"])
print("We sell " + str(num_pizzas) + " different kinds of pizza!")

That integer would have to be changed to a string to add it to other strings in Python.

1 Like