《笨办法学python》加分习题33——我的答案
来源:互联网 发布:淘宝卖家注册账号申请 编辑:程序博客网 时间:2024/05/22 14:40
这是我自己学习的答案,会尽力写的比较好。还望大家能够提出我的不足和错误,谢谢!
**
原文例题:
**
i = 0numbers =[]while i < 6: print "At the top i is %d" % i numbers.append(i) i += 1 print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The numbers: "for num in numbers: print num
**
习题答案:
**
1、
def loop(bout): i = 0 numbers =[] while i < bout: print "At the top i is %d" % i numbers.append(i) i += 1 print "Numbers now: ", numbers print "At the bottom i is %d" % i print "The numbers: " for num in numbers: print num
2、
import ex33ex33.loop(6)print "\n"ex33.loop(4)
3、
def loop(bout): i = 0 numbers =[] while i < bout: print "At the top i is %d" % i numbers.append(i) temp = i + 1 print "Numbers now: ", numbers print "At the bottom i is %d" % temp print "The numbers: " for num in numbers: print num
4、一样的
5、
def loop(bout): numbers = [] for number in range(0, bout): numbers.append(number) print "Numbers now: ", numbersloop(5)
运行结果:
一开始我的for-loop是这样写的:
for number in bout:
然后就一直报错:int' object is not iterable
说是int不能用来迭代,我就去翻看前面的练习和和上网找资料,最后使用的是将bout通过range改为list。
在此感谢:惹不起的程咬金,我在这里得到解释和答案。
阅读全文
1 0
- 《笨办法学python》加分习题33——我的答案
- 《笨办法学python》加分习题1——我的答案
- 《笨办法学python》加分习题2——我的答案
- 《笨办法学python》加分习题3——我的答案
- 《笨办法学python》加分习题4——我的答案
- 《笨办法学python》加分习题5——我的答案
- 《笨办法学python》加分习题6——我的答案
- 《笨办法学python》加分习题7——我的答案
- 《笨办法学python》加分习题8——我的答案
- 《笨办法学python》加分习题9——我的答案
- 《笨办法学python》加分习题10——我的答案
- 《笨办法学python》加分习题11——我的答案
- 《笨办法学python》加分习题12——我的答案
- 《笨办法学python》加分习题13——我的答案
- 《笨办法学python》加分习题14——我的答案
- 《笨办法学python》加分习题15——我的答案
- 《笨办法学python》加分习题16——我的答案
- 《笨办法学python》加分习题17——我的答案
- LeetCode 517. Super Washing Machines
- 矩阵快速幂--最基础的算法,最详细的注释
- 分布式架构概述
- SeetaFace开源人脸识别引擎
- 数据库的故障分类
- 《笨办法学python》加分习题33——我的答案
- openssl C语言编码实现rsa加密
- 如何在Tomcat中配置二级域名
- eclipse怎样在线安装hibernate tools插件并使用
- 一个故事讲完https
- 微信公众号开发(一)服务器及接口的配置
- A Math Problem HDU
- Hibernate框架(1)框架基本搭建
- (五)路由事件