3-1
names=["fang yuan","han ning","yang qinglian","gao henan"]
print(names[0].title())
print(names[1].title())
print(names[2].title())
print(names[3].title())
print(names[0].title())
print(names[1].title())
print(names[2].title())
print(names[3].title())
#注意title后面有()
3-2
names=["fang yuan","han ning","yang qinglian","gao henan"]
print(names[0].title()+", long time no see!")
print(names[1].title()+", long time no see!")
print(names[2].title()+", long time no see!")
print(names[3].title()+", long time no see!")
3-4
guest=["fang yuan","han ning","yang qinglian","gao henan"]
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
3-5(3-9)
guest=["fang yuan","han ning","yang qinglian","gao henan"]
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print(guest[0].title()+" cannot come")
guest[0]="xia mingze"
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print(guest[0].title()+" cannot come")
guest[0]="xia mingze"
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("I have invited "+str(len(guest))+" people for dinner")
3-6
guest=["fang yuan","han ning","yang qinglian","gao henan"]
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("I have found a bigger table!")
guest.insert(0,"xia mingze")
guest.insert(2,"hua xianhe")
guest.append("wang heying")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("Dear "+guest[4].title()+", I want to have dinner with you!")
print("Dear "+guest[5].title()+", I want to have dinner with you!")
print("Dear "+guest[6].title()+", I want to have dinner with you!")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("I have found a bigger table!")
guest.insert(0,"xia mingze")
guest.insert(2,"hua xianhe")
guest.append("wang heying")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("Dear "+guest[4].title()+", I want to have dinner with you!")
print("Dear "+guest[5].title()+", I want to have dinner with you!")
print("Dear "+guest[6].title()+", I want to have dinner with you!")
3-7
guest=["fang yuan","han ning","yang qinglian","gao henan"]
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("I have found a bigger table!")
guest.insert(0,"xia mingze")
guest.insert(2,"hua xianhe")
guest.append("wang heying")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("Dear "+guest[4].title()+", I want to have dinner with you!")
print("Dear "+guest[5].title()+", I want to have dinner with you!")
print("Dear "+guest[6].title()+", I want to have dinner with you!")
print("It is a pity that the table cannot be delivered on time")
pop_guest=guest.pop(2).title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop(5).title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop(3).title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop().title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop().title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
print("Dear "+guest[0].title()+", you are still welcomed to come")
print("Dear "+guest[1].title()+", you are still welcomed to come")
del guest[0]
del guest[0]
print(guest)
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("I have found a bigger table!")
guest.insert(0,"xia mingze")
guest.insert(2,"hua xianhe")
guest.append("wang heying")
print("Dear "+guest[0].title()+", I want to have dinner with you!")
print("Dear "+guest[1].title()+", I want to have dinner with you!")
print("Dear "+guest[2].title()+", I want to have dinner with you!")
print("Dear "+guest[3].title()+", I want to have dinner with you!")
print("Dear "+guest[4].title()+", I want to have dinner with you!")
print("Dear "+guest[5].title()+", I want to have dinner with you!")
print("Dear "+guest[6].title()+", I want to have dinner with you!")
print("It is a pity that the table cannot be delivered on time")
pop_guest=guest.pop(2).title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop(5).title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop(3).title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop().title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
pop_guest=guest.pop().title()
print("Dear "+pop_guest+", sorry the table isn't big enough, and maybe next time!")
print("Dear "+guest[0].title()+", you are still welcomed to come")
print("Dear "+guest[1].title()+", you are still welcomed to come")
del guest[0]
del guest[0]
print(guest)
3-8
places=["Paris","Beijing","Hongkong","London","Shanghai"]
print(places)
print(sorted(places))
print(places)
print(sorted(places,reverse=True))
print(places)
print(sorted(places))
print(places)
print(sorted(places,reverse=True))
#注意reverse和true的大小写
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse=True)
print(places)
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse=True)
print(places)