《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 刚刚往后面看了看