Python编程 从入门到实践 练习3-4~3-7
2020-07-12 17:11
471 查看
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)
相关文章推荐
- Python编程:从入门到实践的动手试一试练习答案(第四章)
- Python编程:从入门到实践--关于测试代码部分的练习
- Python编程从入门到实践:6-11城市练习
- Python编程从入门到实践:6-9喜欢的地方练习
- Python编程 从入门到实践 练习5-8~5-11
- Python编程 从入门到实践 练习5-3~5-7
- Python编程 从入门到实践课后练习10-12
- Python编程 从入门到实践 练习5-1、5-2
- Python编程 从入门到实践 练习4-13
- Python编程 从入门到实践 练习4-10~4-12
- Python编程 从入门到实践练习4-3~4-9
- Python编程 从入门到实践 练习4-1、4-2
- python编程:从入门到实践-第十章练习
- Python编程 从入门到实践 练习3-11
- Python 编程从入门到实践 课后练习2-9
- Python编程:从入门到实践的动手试一试练习答案(第八章)
- Python编程:从入门到实践的动手试一试练习答案(第五章)
- python编程 从入门到实践 第八章 函数 及课后题
- Python编程:从入门到实践--七到九章
- Python编程:从入门到实践(课后习题1)