美文网首页
习题 33 while 循环

习题 33 while 循环

作者: 南北东西总相随 | 来源:发表于2017-10-09 10:56 被阅读0次

    习题 33 while 循环

    # ex33.py
    
    i = 0
    numbers = []
    
    while i < 6:
        print "At the top i is %d" % i
        numbers.append(i)
    
        i = i + 1
        print "Numbers now: ", numbers
        print "At the bottom i is %d" % i
    
    print "The numbers: "
    
    for num in numbers:
        print num
    

    结果:

    $ python ex33.py
    At the top i is 0
    Numbers now:  [0]
    At the bottom i is 1
    At the top i is 1
    Numbers now:  [0, 1]
    At the bottom i is 2
    At the top i is 2
    Numbers now:  [0, 1, 2]
    At the bottom i is 3
    At the top i is 3
    Numbers now:  [0, 1, 2, 3]
    At the bottom i is 4
    At the top i is 4
    Numbers now:  [0, 1, 2, 3, 4]
    At the bottom i is 5
    At the top i is 5
    Numbers now:  [0, 1, 2, 3, 4, 5]
    At the bottom i is 6
    The numbers:
    0
    1
    2
    3
    4
    5
    

    相关文章

      网友评论

          本文标题:习题 33 while 循环

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