首页 > 其他 > 详细

Exercise 33 - while-loop

时间:2019-09-30 13:20:43      阅读:83      评论:0      收藏:0      [点我收藏+]

 

 

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)

output

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

 for-loop

numbers = []

for i in range(0, 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)

 

2019-09-30

17:43:27

Exercise 33 - while-loop

原文:https://www.cnblogs.com/petitherisson/p/11612215.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!