python从入门到实践第三章习题(高级编程技术 week2-1)
2018-03-12 10:29
615 查看
高级编程技术 (week2-1)
3-1
names = ['Mike', 'John', 'Honda'] for name in names: print(name)
3-2 问候语
names = ['Mike', 'John', 'Honda'] for name in names: print(name, ' , how do you do?')
3-3 自己的列表
vicheles = ['by motorcycle','by walk','on foot', 'by taxi']
for vichele in vicheles:
print('I would like to go to school ',vichele)
3-4 、 3-5
这两题主要使用的是列表的基本使用,列表的元素删除,还有列表元素的修改。names = ['Mike', 'John', 'Honda'] for name in names: print(name.title(), "!, would you like to have dinner with me?") busy_name = names.pop(0) print(name.title(), " is too busy to have dinner with me. It's so pity.") for name in names: print(name.title(), "!, would you like to have dinner with me?")
3-6 3-7
这两道题主要练习的是python列表中的insert(),
append()函数的使用。
# 接上一题的程序 print("I find a big table!") names.insert(0, "Lily") names.insert(2, "Kuly") names.append("Xiao Ming") for name in names: print(name.title(), "!, would you like to have dinner with me?") print("But the new table can't get on time. Now I only can invite two friends to my dinner.") while len(names) > 2: delete_name = names.pop() print(delete_name.title(), ", I am sorry to tell you that I can't invite you to my dinner.") for name in names: print(name.title(), ", you still can have dinner with me!") del names[0] del names[0] print(names)
3-11 引发错误
这样的程序能够引发错误test = [1,2,3,4] print(test[4])
运行截图如图所示:
相关文章推荐
- python 从入门到实践第四章习题 (高级编程技术 week2-2)
- python从入门到实践 第八章习题(高级编程技术 week4-2)
- python从入门到实践 第六章习题 (高级编程技术 week3-2)
- python从入门到实践 第十章习题(高级编程技术 week5-2)
- python从入门到实践 第七章习题 (高级编程技术 week4-1)
- python从入门到实践 第九章习题(高级编程技术 week5-1)
- Python 从入门到实践 8-12 课后习题
- 《Python编程 从入门到实践》第三章习题选做
- Python 从入门到实践 7-1 课后习题
- Python编程从入门到实践:习题4-13
- Python 从入门到实践 8-9 课后习题
- python从入门到实践第三章的课后练习作业
- python编程从入门到实践第三章习题答案
- Python 从入门到实践 7-4 课后习题
- 《Python编程-从入门到实践》第三章及第四章习题训练
- 【《Python编程: 从入门到实践》习题答案--第三章:<list 列表简介>】
- Python从入门到实践 习题15-6
- Python 从入门到实践 8-1 课后习题
- Python编程 从入门到实践 第三章 作业参考答案
- Python 从入门到实践 7-8 课后习题