3-2 问候语
names = ['jams', 'tom', 'john']
for name in names:
message = name.title() + ', welcome to the python world!'
print(message)
3-4 嘉宾名单
names = ['Kobe', 'Hawking', 'Einstein', 'Liu Cixin']
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
3-5 修改嘉宾名单
names = ['Kobe', 'Hawking', 'Einstein', 'Liu Cixin']
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
print('Hawking and Einstein can not come.')
names[1] = 'Messi'
names[2] = 'Jackie Chan'
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
3-6 添加嘉宾
names = ['Kobe', 'Hawking', 'Einstein', 'Liu Cixin']
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
print('I find a bigger table.')
names.append('Messi')
names.insert(1, 'Jackie Chan')
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
3-7 缩减名单
names = ['Kobe', 'Hawking', 'Einstein', 'Liu Cixin']
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
print('I find a bigger table.')
names.append('Messi')
names.insert(1, 'Jackie Chan')
for name in names:
message = 'Hi ' + name.title() + ", I'm looking forward to your coming!"
print(message)
print('Sorry, I can only invite two people.')
num = len(names)
for i in range(num - 2):
message = 'Sorry, ' + names[num - 1 - i].title()
print(message)
names.pop()
print(names[0] + ', please coming')
print(names[1] + ', please coming')
del names[0]
del names[0]
print(names)
3-8 放眼世界
places = ['London', 'Paris', 'Alps', 'Dao Cheng', 'New York']
print(places)
print(sorted(places))
print(places)
print(sorted(places, reverse = True))
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse = True)
print(places)