您的位置:首页 > 编程语言 > Python开发

python编程:从入门到实践 第四章课后题

2018-03-17 17:47 323 查看
4-1pizzas = ['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-2animals = ['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-3for i in range(1,21):
print(i,end=' ')4-4numbers = list(range(1,1000001))
for i in numbers:
print(i,end=' ')
#ctrl + c can interrupt4-5import 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-6for i in range(1,21,2):
print(i,end=' ')4-7n3 = list(range(3,31,3))
for i in n3:
print(i,end=' ')4-9n3f = [x**3 for x in range(1,11)]
for i in n3f:
print(i,end=' ')4-10n3 = [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-13foods = ('beef','break','rice','noodle','chicken')
for food in foods:
print(food)

foods = ('beef','pork','rice','noodle','ice cream')
for food in foods:
print(food)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: