pizzas = ["Black Pepper Beef", "New Orleans", "Stuffed Crust Jumbo Shripm Crown"]
for pizza in pizzas:
# print(pizza)
print("I like " + pizza + " pizza.")
print("I really love the taste of pizza")
4-2 动物
animals = ["Tiger", "Lion", "Leopard"]
for animal in animals:
# print(animal)
print("A " + animal + " could be very dangerous.")
print("Any of these animals are very dangerous.")
nums = [value**3forvaluein range(1, 11)]
fornumin nums:
print(num)
print("The first three items in the list are:")
fornumin nums[:3]:
print(num)
print("Three items from the middle of the list are:")
fornumin nums[4:7]:
print(num)
print("The last three items in the list are:")
fornumin nums[-3:]:
print(num)
4-11 你的比萨和我的比萨
pizzas = ["Black Pepper Beef", "New Orleans", "Stuffed Crust Jumbo Shripm Crown"]
for pizza in pizzas:
# print(pizza)
print("I like " + pizza + " pizza.")
print("I really love the taste of pizza")
friend_pizzas = pizzas[:]
pizzas.append("Strange Pizza")
friend_pizzas.append("Normal Pizza")
print("My favorite pizzas are:")
for pizza in pizzas:
print(pizza)
print("My friend's favorite pizzas are")
for pizza in friend_pizzas:
print(pizza)
4-12 使用多个循环
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)
4-13 自助餐
foods = ("rice", "noodle", "bread", "beef", "pork chop")
for food in foods:
print(food)
# foods[1] = "cake"'tuple' object does not support item assignment
print()
foods = ("cake", "chicken", "bread", "beef", "pork chop")
for food in foods:
print(food)