# 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-1
dinner_man[2] = 'Obama' # 3-5-2
print('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-1
dinner_man.insert(0, 'Mao') # 3-6-2
dinner_man.insert(2, 'Jordan') # 3-6-3
dinner_man.append('Phil') # 3-6-4
for 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-1
print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.') # 3-7-2
print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.') # 3-7-2
print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.') # 3-7-2
print(dinner_man.pop() + ', I\'m sorry to be able to invite you to dinner.') # 3-7-2
print(dinner_man[0] + ', you are still in my invitation.') # 3-7-3
print(dinner_man[1] + ', you are still in my invitation.') # 3-7-3
del dinner_man[0] # 3-7-4
del dinner_man[0] # 3-7-4
# 3-8 放眼世界
places = ['Xiamen', 'Lijiang', 'Qingdao', 'Hulunbeier', 'Beihai'] # 3-8-1
print(places) # 3-8-2
print(sorted(places)) # 3-8-3
print(places) # 3-8-4
print(sorted(places, reverse=True)) # 3-8-5
print(places) # 3-8-6
places.reverse(); print(places) # 3-8-7
places.reverse(); print(places) # 3-8-8
places.sort(); print(places) # 3-8-9
places.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]
Python编程:从入门到实践(课后习题3)
原文作者:周小馬
原文地址: https://blog.csdn.net/z120379372/article/details/78027596
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/z120379372/article/details/78027596
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。