当前位置:   article > 正文

python编程从入门到实践第四章习题答案_python机器学习编程与实战教材第四章答案

python机器学习编程与实战教材第四章答案
 
 
4.1
  1. pizza = ['a' , 'b' , 'c' ]
  2. for ele in pizza :
  3. print( ele + " . I like pepperoni pizza." )
  4. print( "They are delicious, I like them" )
4.2
  1. animals = ['dog' , 'cat' , 'bird' ]
  2. for ele in animals :
  3. print( "A " +ele + " would make a great pet" )
  4. print( "Any of these animals would make a great pet" )

 

 
// range 的第三个参数//列表解析:
num = [ v**2 for v in range(1,11) ]
#4.3
  1. for i in range(1,21) :
  2. print( i )
  3. #4.4-4.5
  4. nums = range( 1 , 1000001 )
  5. for ele in nums :
  6. print ( ele )
  7. print ( min(nums) )
  8. print ( max(nums) )
  9. print ( sum(nums) )
  1. #4.6
  2. old = list( range(1,21,2) )
  3. for ele in old :
  4. print( ele )
  5. #4.7nums = range( 3,31,3)
  6. for ele in nums :
  7. print ( ele )
  8. #4.8
  9. nums = []
  10. for i in range(1,11) :
  11. nums.append( i**3 )
  12. for ele in nums :
  13. print ( ele )
  14. #4.9
  15. nums = [v**3 for v in range(1,11) ]
  16. for ele in nums :
  17. print( ele )
  18. #4.10
  19. old = list( range(1,21,2) )
  20. print("The first three items in the list are:" , end = '' )
  21. print( old[:3] )
  22. print ( "Three items from the middle of the list are:" , end = '' )
  23. print( old[2:5] )
  24. print( "The last three items in the list are:" , end = '' )
  25. print( old[-3:] )
  26. #4.11
  27. pizza = ['a' , 'b' , 'c' ]
  28. friend_pizza = pizza[:]pizza.append("D" )friend_pizza.append( 'E' )
  29. print( "My favorite pizzas are: ")for ele in pizza : print( ele )
  30. print( "My friend's favorite pizzas are: " )for ele in pizza : print( ele )
 
#4.13
foods = ('apple' , 'banana' , 'cake' , 'dog' ,'egg' )
foods[1] = 'pear'
foods = ('apple' , 'banana' , 'cake' ,'d' ,'e' )
for ele in foods :  
    print( ele )

 

 

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

闽ICP备14008679号