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]
阅读全文
0 0
- Python编程:从入门到实践(课后习题3)
- Python编程:从入门到实践(课后习题4)
- Python编程:从入门到实践(课后习题5)
- Python编程:从入门到实践(课后习题6)
- Python编程:从入门到实践(课后习题7)
- Python编程:从入门到实践(课后习题8)
- Python编程:从入门到实践(课后习题9)
- Python编程:从入门到实践(课后习题11)
- Python编程:从入门到实践(课后习题10)
- Python 从入门到实践 5-3 课后习题
- Python 从入门到实践 8-3 课后习题
- Python 从入门到实践 5-1 课后习题
- Python 从入门到实践 5-8 课后习题
- Python 从入门到实践 6-1 课后习题
- Python 从入门到实践 6-4 课后习题
- Python 从入门到实践 6-7 课后习题
- Python 从入门到实践 7-1 课后习题
- Python 从入门到实践 7-4 课后习题
- HDU2041 超级楼梯 动态规划入门-递推
- 素材资源网站
- java-rabbitmq-官网实例06
- Rete算法
- ES6_Study
- Python编程:从入门到实践(课后习题3)
- Android基础知识(三)之ListView
- qt dateedit以日历形式显示
- java-rabbitmq-实例pull模式拉取消息
- vuex知识点
- 腾讯 AI Lab 张潼主任带你轻松 get AI 新知识(转载)
- TabLayout+PullToRefreshListView上拉刷新,下拉加载,imageloader自定义
- 【情感分析】基本流程和思路
- 动态规划介绍文章收藏