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

推荐阅读更多精彩内容