《Python编程:从入门到实践》第四章 操作列表 练习题答案

个人学习自用,各位可随便取

#4-1 food
food = ['tomato' , 'orange' , 'banana']
for foods in food:
    print("i like " + foods.title() + " .")
print("i really like banana .")

# 4-2 动物
animals = ['dog' , 'fish' , 'pet']
for animal in animals:
    print("a " + animal.title() + " make a great pet")
print("any of these animals would make a great pet!")

# 4-3 数到20
numbers = list(range(1,21))
print(numbers)

# 4-4 一百万
numbers = list(range(1,100))
print(numbers)

# 4-7 3的倍数
numbers = [value*3 for value in range(1,11)]
print(numbers)

# 4-9 立方解析
numbers = [value**3 for value in range(1,11)]
print(numbers)

# 4-10 切片
foods = ['tomato' , 'orange' , 'banana' , 'apple' , 'ice cream']
print("the first three items in the list are :")
for food in foods[:3]:
    print(food)
print("three items from the middle of the list are :")
for food in foods[1:4]:
    print(food)
print("the last three items in the list are :")
for food in foods[2:]:
    print(food)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值