python编程:从入门到实践
第四章练习:4.1-4.3
#练习4-1
pizzas=['榴莲芝士披萨','水果双拼比萨','海鲜披萨']
for pizza in pizzas:
print(f"I like {pizza}")
print("I really love pizza!")
#练习4-2
animals=['dog','cat','mouse']
for animal in animals:
print(f"A {animal} would make a great pet")
print("Any of these animals will make a greaat pet!")
#练习4-3
for i in range(1,21):
print(i)
#练习4-4
'''number=list(range(1,1000001))
for i in number:
print(i)'''
#练习4-5
number2=list(range(1,1000001))
print(min(number2))
print(max(number2))
print(sum(number2))
#练习4-6
number3=list(range(1,20,2))
for i in number3:
print(i)
#练习4-7
number4=list(range(3,31,3))
for i in number4:
print(i)
#练习4-8
number6=list(range(1,11))
for i in number6:
print(i**3)
#练习4-9
number5=[value**3 for value in range(1,11)]
for i in number5:
print(i)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)