python编程从入门到实践第四章习题
2018-03-15 08:58
399 查看
4.1
// range 的第三个参数//列表解析: num = [ v**2 for v in range(1,11) ]#4.3
#4.13foods = ('apple' , 'banana' , 'cake' , 'dog' ,'egg' )foods[1] = 'pear'foods = ('apple' , 'banana' , 'cake' ,'d' ,'e' )for ele in foods : print( ele )
pizza = ['a' , 'b' , 'c' ] for ele in pizza : print( ele + " . I like pepperoni pizza." ) print( "They are delicious, I like them" )4.2
animals = ['dog' , 'cat' , 'bird' ] for ele in animals : print( "A " +ele + " would make a great pet" ) print( "Any of these animals would make a great pet" )
// range 的第三个参数//列表解析: num = [ v**2 for v in range(1,11) ]#4.3
for i in range(1,21) : print( i ) #4.4-4.5 nums = range( 1 , 1000001 ) for ele in nums : print ( ele ) print ( min(nums) ) print ( max(nums) ) print ( sum(nums) )
#4.6 old = list( range(1,21,2) ) for ele in old : print( ele ) #4.7nums = range( 3,31,3) for ele in nums : print ( ele ) #4.8 nums = [] for i in range(1,11) : nums.append( i**3 ) for ele in nums : print ( ele ) #4.9 nums = [v**3 for v in range(1,11) ] for ele in nums : print( ele ) #4.10 old = list( range(1,21,2) ) print("The first three items in the list are:" , end = '' ) print( old[:3] ) print ( "Three items from the middle of the list are:" , end = '' ) print( old[2:5] ) print( "The last three items in the list are:" , end = '' ) print( old[-3:] ) #4.11 pizza = ['a' , 'b' , 'c' ] friend_pizza = pizza[:]pizza.append("D" )friend_pizza.append( 'E' ) print( "My favorite pizzas are: ")for ele in pizza : print( ele ) print( "My friend's favorite pizzas are: " )for ele in pizza : print( ele )
#4.13foods = ('apple' , 'banana' , 'cake' , 'dog' ,'egg' )foods[1] = 'pear'foods = ('apple' , 'banana' , 'cake' ,'d' ,'e' )for ele in foods : print( ele )
相关文章推荐
- 《Python编程 从入门到实践》第四章课后习题
- 《Python编程——从入门到实践》第四章部分习题解
- 《Python编程 从入门到实践》第四章习题选做
- 【《Python编程: 从入门到实践》习题答案--第四章:<list 列表操作>】
- 《Python编程-从入门到实践》第三章及第四章习题训练
- python编程从入门到实践第八章习题
- Python编程从入门到实践:习题6-1~6-3
- 《Python编程-从入门到实践》课后习题(3)
- 《Python编程-从入门到实践》课后习题(4)
- 《Python编程——从入门到实践》第五章部分习题解
- 《Python编程 从入门到实践》第十章课后习题
- Python编程从入门到实践:习题4-10~4-12
- [置顶] 【Python编程: 从入门到实践】习题答案(目录索引)
- 《Python编程——从入门到实践》第二章习题解
- python编程从入门到实践第二章习题答案
- Python编程从入门到实践习题5
- 《Python编程从入门到实践》第四章的动手414
- [Python编程:从入门到实践] 第十五章:生成数据 习题答案
- Python编程:从入门到实践(课后习题6)
- 《Python编程-从入门到实践》课后习题(2)