美文网首页
ex33 while循环

ex33 while循环

作者: 果三代 | 来源:发表于2016-03-22 22:31 被阅读17次

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循环也是一个很好的选择

相关文章

网友评论

      本文标题:ex33 while循环

      本文链接:https://www.haomeiwen.com/subject/xnsllttx.html