当前位置:   article > 正文

Python编程 从入门到实践 第四章 作业参考答案 (部分)_头歌实践教学平台答案pyhon第四章作业

头歌实践教学平台答案pyhon第四章作业

4-2 动物

  1. animals = ["dog","cat","panda","squirrel"]
  2. for a in animals:
  3. print(a.title())
  4. for a in animals:
  5. print("A",a,"could be so cute!")
  6. print("Any of these could be a cute icon!")
  1. Dog
  2. Cat
  3. Panda
  4. Squirrel
  5. A dog could be so cute!
  6. A cat could be so cute!
  7. A panda could be so cute!
  8. A squirrel could be so cute!
  9. Any of these could be a cute icon!

4-5 一百万

  1. million = list(range(1,1000001))
  2. print(min(million))
  3. print(max(million))
  4. print(sum(million))
  1. 1
  2. 1000000
  3. 500000500000

4-6 4-7 奇数 3的倍数

  1. odds = list(range(1,21,2))
  2. for odd in odds:
  3. print(odd)
  4. print('---------')
  5. times3 = list(range(3,31,3))
  6. for t3 in times3:
  7. print(t3)
  1. 1
  2. 3
  3. 5
  4. 7
  5. 9
  6. 11
  7. 13
  8. 15
  9. 17
  10. 19
  11. ---------
  12. 3
  13. 6
  14. 9
  15. 12
  16. 15
  17. 18
  18. 21
  19. 24
  20. 27
  21. 30

4-9 列表解析

  1. mylist = [num**3 for num in range(1,11)]
  2. print(mylist)
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

4-10 切片

  1. animals = ["dog","cat","panda","squirrel"]
  2. print("The first three items:",animals[:3])
  3. print("Three items from the middle of the list are:",animals[1:4])
  4. print("The last three items are:",animals[-3:])
  1. The first three items: ['dog', 'cat', 'panda']
  2. Three items from the middle of the list are: ['cat', 'panda', 'squirrel']
  3. The last three items are: ['cat', 'panda', 'squirrel']

4-13 自助餐,略

(元组元素不能被修改)


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/402545
推荐阅读
相关标签
  

闽ICP备14008679号