4-1
pizzas = ['Seafood pizza','Sausage pizza','Cheese pizza','Beef pizza']
for pizza in pizzas:
print(pizza)
for pizza in pizzas:
print("I like " + pizza + '.')
print("I really love pizza!")
4-2
animals = ['dog','cat','bird']
for an in animals:
print(an)
for an in animals:
print("A " + an + " would make a great pet.")
print("Any of these animals would make a great pet!")
4-3
for i in range(1,21):
print(i,end=' ')
4-4
numbers = list(range(1,1000001))
for i in numbers:
print(i,end=' ')
#ctrl + c can interrupt
4-5
import time
numbers = list(range(1,1000001))
print(min(numbers))
print(max(numbers))
t1 = time.clock()
s = sum(numbers)
t2 = time.clock()
print(s)
print(t2-t1)
4-6
for i in range(1,21,2):
print(i,end=' ')
4-7
n3 = list(range(3,31,3))
for i in n3:
print(i,end=' ')
4-9
n3f = [x**3 for x in range(1,11)]
for i in n3f:
print(i,end=' ')
4-10
n3 = [x**3 for x in range(1,11)]
print("The first three items in the list are: ", n3[0:3])
print("Three items from the middle of the list are: ", n3[3:6])
print("The last three items in the list are: ",n3[-3:])
4-13
foods = ('beef','break','rice','noodle','chicken')
for food in foods:
print(food)
foods = ('beef','pork','rice','noodle','ice cream')
for food in foods:
print(food)