Python编程第三章课后习题

3-4~3-6

#3-4
lists  = ["A","B","C","D","E"]
print(lists)

#3-5
lists.remove('B')
print(lists)
print(f"\nMr.B is too busy to join this activity")

#3-6
print("Lucky! Find a bigger table!" )

lists.remove('E')
lists.insert(0,'E')
print(lists)

lists.insert(2,'T')
print(lists)

lists.append('X')
print(lists)

3-7


print('I am sorry about only two guests can come this party')

for n in range(0,4):
    number=1
    number+=1
    leave = lists.pop(number)
    print(leave+" sorry for that you can not come party")
for n in range(0,2):
    print("congratuation "+ lists[0] +" you can come party")
    
print(lists)

3-8

#3-8
places = ['Tokyo','London','San Diego','Beijing','New York']
print(places)
#
print(sorted(places))
#
print(places)
#
print(sorted(places,reverse=True))
#
print(places)
#
places.reverse()
print(places)
#
places.reverse()
print(places)
#
places.sort()
print(places)
#
places.sort(reverse=True)
print(places)

3-9

#3-9
print(len(lists))

3-10

#喜欢的美女
beauty = ['蒙嘉慧','蛇姐','林允儿','小茜','斋藤飞鸟','刘浩存']
#增加元素
beauty.append('冬宝')
print('我喜欢的人美女有')
print(beauty)
#插入元素
beauty.insert(3,'欢欢')
print('\n加了欢欢,现在我喜欢的美女有')
print(beauty)
#删除元素del
del beauty[4]
print('\n删了四号,现在喜欢的美女有')
print(beauty)
#删除元素pop
print('\n删除的美女是')
print(beauty.pop(5))
#删除元素remove
beauty.remove('斋藤飞鸟')
print('\n删除了斋藤飞鸟,现在喜欢的美女有')
print(beauty)
#对美女进行排序sort
beauty.sort()
print('\n对美女进行按字母排序')
print(beauty)
#对美女进行相反排序sorted
print('\n这是美女排序')
print(beauty)
print('这是现在美女的排序')
print(sorted(beauty,reverse=True))
print('这是原来的美女排序')
print(beauty)
#倒着打印reverse
beauty.reverse()
print('\n倒着打印美女排序')
print(beauty)
#确定长度
print('\n美女一共有')
print(len(beauty))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牛有果真的是你啊啊啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值