3-4 嘉宾名单
guest_list = ['alice', 'bob', 'carmen', ]
print(guest_list[0].title() + ',please come and have dinner with me.')
print(guest_list[1].title() + ',please come and have dinner with me.')
print(guest_list[2].title() + ',please come and have dinner with me.')
3-5 修改嘉宾名单
guest_list = ['alice', 'bob', 'carmen', ]
unable_guest = guest_list.pop(1)
new_guest = 'beer'
guest_list.insert(1,new_guest)
print(guest_list[0].title() + ',please come and have dinner with me.')
print(guest_list[1].title() + ',please come and have dinner with me.')
print(guest_list[2].title() + ',please come and have dinner with me.')
print(unable_guest.title() + ' unable to attend.')
3-6 添加嘉宾
guests = ['alice', 'bob', 'carmen', ]
unable_guest = guests.pop(1)
new_guest = 'beer'
guests.insert(1,new_guest)
guests.insert(0,'david')
guests.insert(2,'Eric')
guests.append('ford')
print(guests[0].title() + ',please come and have dinner with me.')
print(guests[1].title() + ',please come and have dinner with me.')
print(guests[2].title() + ',please come and have dinner with me.')
print(guests[3].title() + ',please come and have dinner with me.')
print(guests[4].title() + ',please come and have dinner with me.')
print(guests[5].title() + ',please come and have dinner with me.')
print(unable_guest.title() + ' unable to attend.')
print('I find a bigger table.')
3-7 缩减名单
guests = ['alice', 'bob', 'carmen', ]
unable_guest = guests.pop(1)
new_guest = 'beer'
guests.insert(1,new_guest)
guests.insert(0,'david')
guests.insert(2,'Eric')
guests.append('ford')
print(guests[0].title() + ',please come and have dinner with me.')
print(guests[1].title() + ',please come and have dinner with me.')
print(guests[2].title() + ',please come and have dinner with me.')
print(unable_guest.title() + ' unable to attend.')
print('I find a bigger table.')
print(guests[3].title() + ',please come and have dinner with me.')
print(guests[4].title() + ',please come and have dinner with me.')
print(guests[5].title() + ',please come and have dinner with me.')
print(guests.pop().title() + ",sorry can't invite you to dinner.")
print(guests.pop().title() + ",sorry can't invite you to dinner.")
print(guests.pop().title() + ",sorry can't invite you to dinner.")
print(guests.pop().title() + ",sorry can't invite you to dinner.")
print(guests[0].title() + ' is still invited.')
print(guests[1].title() + ' is still invited.')
print('I can only invite two guests to come and have dinner with me.')
del guests[1]
del guests[0]
print(guests)