python學習第2周(2)

#4-2
animals = ["dog", "cat", "pig"]
for animal in animals :
print("A " + animal + " would make a great pet")
print("Any of the animals would make a great pet!")


#4-3
for value in range(1, 21):
print(value)


#4-4
numbles = list(range(1,1000001))
print(min(numbles))
print(max(numbles))
print(sum(numbles))


#4-7
list1 = list(range(3,31,3))
for value in list1:
print(value)

#4-9
squares = [value**2 for value in range(1,11)]
for value in squares :
print(value)


#4-10
print("The first three items in the list are:")
print(squares[:3])
print("Three items from the middle of the list are:")
print(squares[4:7])
print("The last three items in the list are:")
print(squares[-3:])

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章