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)
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)
相关文章推荐
- 《Python编程 从入门到实践》第四章课后习题
- Python编程:从入门到实践,课后题15-7
- Python编程:从入门到实践(课后习题10)
- 《Python编程-从入门到实践》课后习题(9)
- 《Python编程:从入门到实践》课后练习2-1到2-11
- 《Python编程-从入门到实践》课后习题(3)
- python编程从入门到实践第四章习题
- Python编程:从入门到实践,课后题15-9
- 《Python编程:从入门到实践》课后练习6-1到6-11
- Python编程:从入门到实践,课后题13-5
- 《Python编程从入门到实践》第四章的动手414
- python编程:从入门到实践课后作业(一)
- 【《Python编程: 从入门到实践》习题答案--第四章:<list 列表操作>】
- 《Python编程——从入门到实践》第四章部分习题解
- 《Python编程:从入门到实践》课后练习5-1到5-11
- 《Python编程-从入门到实践》课后习题(1)
- 《Python编程 从入门到实践》第四章习题选做
- 《Python编程 从入门到实践》第五章课后习题
- 《Python编程-从入门到实践》课后习题(5)
- 《Python编程-从入门到实践》课后习题(6)