pizzas = ['apple pizza','banana pizza','chili pizza']
for pizza in pizzas:
print('I like ' + pizza.title())
print('\nI really love pizza!')
animals = ['dog','cat','horse']
for animal in animals:
print('A ' + animal + ' would make a great pet')
print('\nAny of these animals would make a great pet!')
for x in range(1,21):
print(x)
numbers = []
for x in range(1,1000001):
numbers.append(x)
for number in numbers:
print(number)
#4-5 计算1~1 000 000的总和
numbers = []
for x in range(1,1000001):
numbers.append(x)
print(min(numbers))
print(max(numbers))
print(sum(numbers))
numbers = []
for x in range(1,20,2):
numbers.append(x)
for number in numbers:
print(number)
numbers = []
for x in range(3,31,3):
numbers.append(x)
for number in numbers:
print(number)
numbers = []
for x in range(1,11):
numbers.append(x**3)
for number in numbers:
print(number)
numbers = [x**3 for x in range(1,11)]
for number in numbers:
print(number)
numbers = [x**3 for x in range(1,11)]
for number in numbers:
print(number)
print('The first three items in the list are:')
print(numbers[0:3])
print('Three items from the middle of the list are:')
print(numbers[3:6])
print('The last three items in the list are:')
print(numbers[-3:])
pizzas = ['apple pizza','banana pizza','chili pizza']
for pizza in pizzas:
print('I like ' + pizza.title())
print('\nI really love pizza!')
friend_pizzas = pizzas[:]
pizzas.append('milk pizza')
friend_pizzas.append('black pizza')
print('\nMy 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','apple','banana')
for food in foods:
print(food)
foods = ('pizza', 'beef', 'milk','apple','banana')
for food in foods:
print(food)