《Python编程从入门到实践》习题01

《Python编程从入门到实践》——动手试一试

6月3号,纪念Uzi退役。永远的神!!!!
题干:本书38页
4个小实验整合到一起了,新手代码质量太差了,写的非常简单。等以后学到后面的,再来改进。(●’◡’●)

#我想和这些人打LOL
competitors=["jacklove",'theshy','Uzi',"Rookie"]
message="Hello!"+"I want to have a lol play with "+str(competitors)+'.'
print(message)
print(competitors[2]+" can't attend!")
del competitors[2]
competitors.insert(2,'Feaker')
message="Hello!"+"I want to have a lol play with "+str(competitors)+'.'
print(message)
print("I find a lager table which can hold three more people!")
competitors.insert(0,'Sanmu')
competitors.append('Zoom')
t=len(competitors)
competitors.insert(t//2,'Puff')
message="Hello!"+"I want to have a lol play with "+str(competitors)+'.'
print(message)
print("Sorry,I can only paly with tow competitors.")
t=competitors.pop()
print("Sorry,i don't want to play with "+t)
t=competitors.pop()
print("Sorry,i don't want to play with "+t)
t=competitors.pop()
print("Sorry,i don't want to play with "+t)
t=competitors.pop()
print("Sorry,i don't want to play with "+t)
t=competitors.pop()
print("Sorry,i don't want to play with "+t)
message="Hello!"+"I want to have a lol play with "+str(competitors)+'.'
print(message)
del competitors[0]
del competitors[0]
print(competitors)
print("List has been cleaned.")
Hello!I want to have a lol play with ['jacklove', 'theshy', 'Uzi', 'Rookie'].
Uzi can't attend!
Hello!I want to have a lol play with ['jacklove', 'theshy', 'Feaker', 'Rookie'].
I find a lager table which can hold three more people!
Hello!I want to have a lol play with ['Sanmu', 'jacklove', 'theshy', 'Puff', 'Feaker', 'Rookie', 'Zoom'].
Sorry,I can only paly with tow competitors.
Sorry,i don't want to play with Zoom
Sorry,i don't want to play with Rookie
Sorry,i don't want to play with Feaker
Sorry,i don't want to play with Puff
Sorry,i don't want to play with theshy
Hello!I want to have a lol play with ['Sanmu', 'jacklove'].
[]
List has been cleaned.

6月4号:
加了循环的列表的基本操作:

competitors=['Sanmu', 'jacklove', 'theshy', 'Puff', 'Feaker', 'Rookie', 'Zoom']
for x in competitors[2:]:
    competitors.pop()
message="Hello!"+"I want to have a lol play with "+str(competitors)+'.'

competitors.clear()
print(competitors)
print("List has been cleaned.")

题干:书本42页

competitors=["Jacklove",'Theshy','Uzi',"Rookie",'Feaker']
print(competitors)
print(sorted(competitors))
print(competitors)
print(sorted(competitors,reverse=True))
print(competitors)
competitors.reverse()
print(competitors)
competitors.reverse()
print(competitors)
competitors.sort()
print(competitors)
competitors.sort(reverse=True)
print(competitors)
print("I invited "+str(len(competitors))+' people'+'.')
['Jacklove', 'Theshy', 'Uzi', 'Rookie', 'Feaker']
['Feaker', 'Jacklove', 'Rookie', 'Theshy', 'Uzi']
['Jacklove', 'Theshy', 'Uzi', 'Rookie', 'Feaker']
['Uzi', 'Theshy', 'Rookie', 'Jacklove', 'Feaker']
['Jacklove', 'Theshy', 'Uzi', 'Rookie', 'Feaker']
['Feaker', 'Rookie', 'Uzi', 'Theshy', 'Jacklove']
['Jacklove', 'Theshy', 'Uzi', 'Rookie', 'Feaker']
['Feaker', 'Jacklove', 'Rookie', 'Theshy', 'Uzi']
['Uzi', 'Theshy', 'Rookie', 'Jacklove', 'Feaker']
I invited 5 people.

第一个好像用循环简单好多0.0 刚刚往后面看了看

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值