ex33 while循环

ex33

i = 0
numbers = []

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" % i

print "The numbers:"
for num in numbers:
    print num

作业代码





def num(max, const):
    i = 0
    numbers = []
    while i < max:
        print "At the top i is %d " % i 
        numbers.append(i)

        i += const
        print "Numbers now:", numbers
        print "At the bottom i is %d" % i

print num(6, 2)

numbers = []
for x in range(0,6,2):
    numbers.append(x)
    print numbers

for循环和while循环有什么区别?
for循环只能对某种事物的集合做循环,而while可以进行任何种类的循环,但是,while循环很容易出错,大部分情况for循环也是一个很好的选择

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,778评论 18 399
  • 第一部分 打好基础 Laying the Foundation 第一章 欢迎进入软件构建的世界 Welcome t...
    白桦叶阅读 4,707评论 0 17
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,556评论 25 708
  • 从小,都是很乖一直听爸爸妈妈的话。除了性格内向,学校成绩平平,应该还算是那种可以人堆里,抓一大把一样的女孩子。偏偏...
    半仙公子阅读 177评论 0 0
  • 时光打马而过,我们落花成年。 还来不及感叹“偶像”更迭速度的频繁,前有归国四子、后有T-FBOYS,蓦然回首,发现...
    杜晓宇Pro阅读 469评论 0 1