pizzas
=['sausage pizza','cheese pizza','beef pizza']
for pizza
in pizzas
:
print("I like "+pizza
+".")
print("I really love pizza!")
animals
=['dog','cat','pig']
for animal
in animals
:
print("A "+animal
+" would make a great pet.")
print("Any of these animals would make a great pet!")
squares
= []
for value
in range(1,21):
square
= value
squares
.append
(square
)
print(squares
)
for value
in range(1,1000001):
print(value
)
listing
=[]
for value
in range(1,1000001):
listing
.append
(value
)
print(listing
)
print(min(listing
))
print(max(listing
))
print(sum(listing
))
listing
=[]
for value
in range(1,21,2):
listing
.append
(value
)
print(listing
)
threes
= list(range(3, 31, 3))
for number
in threes
:
print(number
)
threes
= list(range(1,11))
for number
in threes
:
print(number
**3)
cube
=[value
**3 for value
in range(1,11)]
print(cube
)
my_foods
=['pizza','falafel','carrot cake','ice cream','rice']
print("the first three items in the list are")
print(my_foods
[0:3])
print("There items from the middle of the list are")
print(my_foods
[1:4])
print("the last three items in the list are")
print(my_foods
[-3:])
pizzas
=['sausage pizza','cheese pizza','beef pizza']
friend_pizzas
=pizzas
[:]
pizzas
.append
('seafood pizza')
friend_pizzas
.append
('corn pizza')
print("My favorite pizzas are:")
for pizza
in pizzas
:
print(pizza
)
print("\nMy friend’s favorite pizzas are:")
for friend_pizza
in friend_pizzas
:
print(friend_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 my_food
in my_foods
:
print(my_food
)
print("\nMy friend's favorite foods are:")
for friend_food
in friend_foods
:
print(friend_food
)
menu
=('Smoked Salmon','Whole Wheat Bread','Turkey','Fried Eggs with Ham','Vanilla Pudding')
print("Original menu:")
for food
in menu
:
print(food
)
menu
=('Grilled Stuffed Chicken Rolls','Whole Wheat Bread','Pasta','Fried Eggs with Ham','Vanilla Pudding')
print("\nModified menu:")
for food
in menu
:
print(food
)
转载请注明原文地址:https://blackberry.8miu.com/read-18202.html