python编程:从入门到实践习题第四章4-10~4-11

4-10 切片:
选择你在本章编写的一个程序,在末尾添加几行代码,以完成如下任务。

 打印消息“The first three items in the list are:”,再使用切片来打印列表的前三个 元素。

 打印消息“Three items from the middle of the list are:”,再使用切片来打印列表中 间的三个元素。

 打印消息“The last three items in the list are:”,再使用切片来打印列表末尾的三 个元素。

list=[value**3 for value in range(1,11)]

print(list)

for num in list:

    print(num)

print("The first three items in the list are:")

print(list[:3])

print("Three items from the middle of the list are:")

print(list[1:4])

print("The last three items in the list are:")

print(list[-3:])

4-11 你的比萨和我的比萨:
在你为完成练习 4-1而编写的程序中,创建比萨列表的 副本,并将其存储到变量 friend_pizzas 中,再完成如下任务。

 在原来的比萨列表中添加一种比萨。

 在列表 friend_pizzas 中添加另一种比萨。

 核实你有两个不同的列表。为此,打印消息“My favorite pizzas are:”,再使用一 个 for 循环来打印第一个列表;打印消息“My friend’s favorite pizzas are:”,

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值