修改这个for 循环,使其打印包含比萨名称的句子,而不仅仅是比萨的名称。对于每种比萨,都显示一行输出,如“I like pepperoni pizza”。
在程序末尾添加一行代码,它不在for 循环中,指出你有多喜欢比萨。输出应包含针对每种比萨的消息,还有一个总结性句子,如“I really love pizza!”。
pizzas = [‘Neapolitan pizza‘,‘pepperoin pizza‘,‘pan pizza‘]
for pizza in pizzas:
print(f"I like {pizza}")
for pizza in pizzas:
print("I really like " + pizza +"very much")
print("I really love pizza")
pets = [‘dog‘,‘cat‘,‘tortoise‘]
for pet in pets:
print(f"A {pet} would make a great pet")
print("\nAny of these animals would make a great pet!")
for value in range(1,21):
print(value)
#method two
values = [value for value in range(1,21)]
print(values)
for value in range(1,10 ** 6 +1):
print(value)
values = [value for value in range(1,10 ** 6 +1)]
print(min(values))
print(max(values))
print(sum(values))
odd_numbers = [value for value in range(1,20,2)]
print(odd_numbers)
three_numbers = [value for value in range(3,30,3)]
print(three_numbers)
#method two
for value in range(3,30,3):
print(value)
cubes = []
for value in range(1,11):
cube = value ** 3
cubes.append(cube)
print(cubes)
cubes = [value ** 3 for value in range(1,11)]
print(cubes)
players = [‘charles‘,‘martina‘,‘michael‘,‘florence‘,‘eli‘]
print("The first three items in the list are:")
three_players = players[:3]
print(three_players)
print("\nThree items from the middle of the list are:")
# print(int((len(players)-3)/2))
# print(int((len(players)-3)/2)+3)
three_players2 = players[int((len(players)-3)/2):int((len(players)-3)/2)+3]
print(three_players2)
print("\nThe last three items in the list are:")
print(players[-3:])
pizzas = [‘Neapolitan pizza‘,‘pepperoin pizza‘,‘pan pizza‘]
friend_pizzas = pizzas[:]
pizzas.append("Domino‘s Pizza")
friend_pizzas.append("ROC Pizza")
print("My favorite pizzas are:")
for pizza in pizzas:
print(pizza)
print("\nMy friend‘s favorite pizzas are:")
for pizza in friend_pizzas:
print(pizza)
my_foods = [‘pizza‘,‘falafel‘,‘carrot‘,‘cake‘]
friend_foods = my_foods[:]
my_foods.append("cannoli")
friend_foods.append("ice cream")
print("My favorite foods are:")
for food in my_foods:
print(food)
print("\nMy friend‘s favorite foods are:")
for food in friend_foods:
print(food)
foods = (‘pizza‘,‘falafel‘,‘carrot‘,‘cake‘,‘ice cream‘)
for food in foods:
print(food)
# foods[2] =‘cannoli‘ 核实Python确实会拒绝这样做
print("\nModified the menu")
foods =(‘pizza‘,‘falafel‘,‘cake‘,‘cannoli‘,‘tomato‘)
for food in foods:
print(food)
原文:https://www.cnblogs.com/CodingXu-jie/p/12727841.html