第三章 动手试一试
3-1 姓名/3-2 问候语
names=['xiaomei', 'yanyan', 'wenhua']
print(names[0].title())
print(names[-2].title())
print(names[-1].title())
message="Hello "+names[0]+", how are you?"
print(message)
3-3 自己的列表
commute_styles=['bus', 'bike', 'subway', 'car']
message1="I would like to own a BMW "+commute_styles[-1]+"."
print(message1)
message2="But I think by "+commute_styles[-2]+" is a wise choice when commute traffic is heavy."
print(message2)
3-4 嘉宾名单
name_list=['daddy', 'mommy', 'niuniu']
message1=name_list[0].title()+", I would like to invite you to have a dinner, OK?"
print(message1)
message2=name_list[1].title()+", do you want to have a dinner with me?"
print(message2)
message3=name_list[-1].title()+", let's go to KFC to have a dinner."
print(message3)
3-5 修改嘉宾名单/3-6/3-7
name_list=['daddy', 'mommy', 'niuniu']
message=name_list[0].title()+" has been invited to have dinner with his officiers."
print(message)
name_list.pop(0)#删除无法参加的嘉宾姓名
print(name_list)
name_list.insert(0, 'huasband')#替换新邀请的嘉宾姓名
print(name_list)
message1=name_list[0].title()+", I would like to invite you to have a dinner, OK?"
print(message1)
message2=name_list[1].title()+", do you want to have a dinner with me?"
print(message2)
message3=name_list[-1].title()+", let's go to KFC to have a dinner."
print(message3)
print("I have find a bigger table, so I want to invite more guests to have a dinner.")#找到更大餐桌
name_list.insert(0,'chunchun')#添加新嘉宾
name_list.insert(2,'erbao')
name_list.append('aunt')
print(name_list)
message1=name_list[0].title()+", I would like to invite you to have a dinner, OK?"
print(message1)
message2=name_list[1].title()+", do you want to have a dinner with me?"
print(message2)
message3=name_list[-1].title()+", let's go to KFC to have a dinner."
print(message3)
print("I am so sorry that I can invite only two persons, because the delivering of table has troubles.")#只能邀请两位嘉宾共进晚餐
poped_name1=name_list.pop()#弹出嘉宾名单
print(poped_name1+", I am so sorry.")
poped_name2=name_list.pop()
3-8 放眼世界
visit_places=['New Zealand', 'Guangzhou', 'Beihaidao']
print(visit_places)
print(sorted(visit_places))
print(visit_places)
print(sorted(visit_places, reverse=True))
print(visit_places)
visit_places.reverse()
print(visit_places)
visit_places.reverse()
print(visit_places)
visit_places.sort()
print(visit_places)
visit_places.sort(reverse=True)
print(visit_places)
3-9 晚餐嘉宾
name_list=['daddy','mommy','niuniu']
len(name_list)#3-9 晚餐嘉宾
3-10已经在本章的练习中体现到了,在这里就不给出代码了