Python编程:从入门到实践(课后习题3)

来源:互联网 发布:java源码如何变成软件 编辑:程序博客网 时间:2024/05/18 02:28
# 3-1 姓名names = ['Zhou Kai', 'Zhang Lili', 'Liu Jie', 'Zhou Ting', 'Zhou Jing']for i in names:print(i)# 3-2 问候语names = ['Zhou Kai', 'Zhang Lili', 'Liu Jie', 'Zhou Ting', 'Zhou Jing']for i in names:print('Hello, ' + i + '.')# 3-3 自己的列表commutes = ['Bicycle', 'Car', 'Buss', 'Train', 'Airplane']for i in commutes:print('I would like to own a ' + i + '.')# 3-4 嘉宾名单dinner_man = ['Kobe', 'Eason', 'Xi']print('Dear ' + dinner_man[0] + ', ' + dinner_man[1] + ', ' + dinner_man[2]      + ',' + 'I\'d like to have dinner with you.')# 3-5 修改嘉宾名单print(dinner_man[2] + ' can not make an appointment.')  # 3-5-1dinner_man[2] = 'Obama'  # 3-5-2print('Dear ' + dinner_man[0] + ', ' + dinner_man[1] + ', ' + dinner_man[2]      + ',' + 'I\'d like to have dinner with you.')  # 3-5-3# 3-6 添加嘉宾print('Dear ' + dinner_man[0] + ', ' + dinner_man[1] + ', ' + dinner_man[2]      + ',' + 'I found a bigger table.')  # 3-6-1dinner_man.insert(0, 'Mao')  # 3-6-2dinner_man.insert(2, 'Jordan')  # 3-6-3dinner_man.append('Phil')  # 3-6-4for i in dinner_man:    print('Dear ' + i + ',I\'d like to have dinner with you.')  # 3-6-5# 3-7 缩减名单print('I am sorry to tell you that because the big table can not be sent in \time, so I can only invite two guests to dinner.')  # 3-7-1print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.')  # 3-7-2print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.')  # 3-7-2print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.')  # 3-7-2print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.')  # 3-7-2print(dinner_man[0] + ', you are still in my invitation.')  # 3-7-3print(dinner_man[1] + ', you are still in my invitation.')  # 3-7-3del dinner_man[0]  # 3-7-4del dinner_man[0]  # 3-7-4# 3-8 放眼世界places = ['Xiamen', 'Lijiang', 'Qingdao', 'Hulunbeier', 'Beihai']  # 3-8-1print(places)  # 3-8-2print(sorted(places))  # 3-8-3print(places)  # 3-8-4print(sorted(places, reverse=True))  # 3-8-5print(places)  # 3-8-6places.reverse(); print(places)  # 3-8-7places.reverse(); print(places)  # 3-8-8places.sort(); print(places)  # 3-8-9places.sort(reverse=True); print(places)  # 3-8-10# 3-9 晚餐嘉宾print(len(dinner_man))# 3-11 有意引发错误list1 = ['sdsa', 123, '卡扣']list1[3]  # 引发错误len(list1)list1[2]

原创粉丝点击