第33个python程序:while循环
2016-09-30 15:36
141 查看
[root@mysql1 pshell]# cat ex33.py
#!/usr/bin/env Python
#-*-coding:utf-8-*-
i=0
numbers=[]
while i<6:
print "at the top i is %d" % i
numbers.append(i)
i=i+1
print "numnbers now: ", numbers
print "at the bottom i is %d" % i
print "the numbers: "
for num in numbers:
print num
[root@mysql1 pshell]#
[root@mysql1 pshell]#
[root@mysql1 pshell]#
[root@mysql1 pshell]#
[root@mysql1 pshell]# python ex33.py
at the top i is 0
numnbers now: [0]
at the bottom i is 1
at the top i is 1
numnbers now: [0, 1]
at the bottom i is 2
at the top i is 2
numnbers now: [0, 1, 2]
at the bottom i is 3
at the top i is 3
numnbers now: [0, 1, 2, 3]
at the bottom i is 4
at the top i is 4
numnbers now: [0, 1, 2, 3, 4]
at the bottom i is 5
at the top i is 5
numnbers now: [0, 1, 2, 3, 4, 5]
at the bottom i is 6
the numbers:
0
1
2
3
4
5
#!/usr/bin/env Python
#-*-coding:utf-8-*-
i=0
numbers=[]
while i<6:
print "at the top i is %d" % i
numbers.append(i)
i=i+1
print "numnbers now: ", numbers
print "at the bottom i is %d" % i
print "the numbers: "
for num in numbers:
print num
[root@mysql1 pshell]#
[root@mysql1 pshell]#
[root@mysql1 pshell]#
[root@mysql1 pshell]#
[root@mysql1 pshell]# python ex33.py
at the top i is 0
numnbers now: [0]
at the bottom i is 1
at the top i is 1
numnbers now: [0, 1]
at the bottom i is 2
at the top i is 2
numnbers now: [0, 1, 2]
at the bottom i is 3
at the top i is 3
numnbers now: [0, 1, 2, 3]
at the bottom i is 4
at the top i is 4
numnbers now: [0, 1, 2, 3, 4]
at the bottom i is 5
at the top i is 5
numnbers now: [0, 1, 2, 3, 4, 5]
at the bottom i is 6
the numbers:
0
1
2
3
4
5
相关文章推荐
- Python While循环语句 Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: while 判断条件:
- python学习之语句:循环语句(for,while)
- Learn Python The Hard Way学习(33) - While循环
- 跟老齐学Python之用while来循环
- 第9周 项目2-1 运用while语句做循环程序求正负分数累加和
- 第9周 项目1-3 运用do-while语句做循环程序求和
- 用WHILE循环编程,输出10到0递减的自然数,然后用FOR循环重写该程序
- 3-3-3 while循环-验证程序
- 通过while实现程序的无限循环
- 编写程序,将用分钟表示的时间转换成以小时 和分钟表示的时间。使用#define来创建一个代 表60的符号常量。使用while循环来允许用户重 复键入值并当键入一个小于等于0的时间是终止循环。
- [第3天] 程序的控制结构 (循环)[while]、[do while]、[for]
- python while循环实例
- 下面程序为什么没有一直陷入main的while(1)循环?(多线程在作怪)
- Python while循环语法
- Python While循环语句
- python语言if判断,for,while循环,自编的小例子,规范版
- Python学习笔记--for, while循环后面加else的作用
- 用 while 循环编程,输出 10 到 0 递减的自然数。然后用 for 循环重写该程序
- 【DB.PL/SQL】程序流程控制 —— 循环 ——LOOP, END LOOP, WHILE, FOR, CONTINUE
- python中while循环和for循环的用法