Python探索记(06)——while

简介: 请看如下示例:# @Time : 2017/7/2 15:54# @Author : 原创作者:谷哥的小弟# @Site : 博客地址:http://blog.

请看如下示例:

# @Time    : 2017/7/2 15:54
# @Author  : 原创作者:谷哥的小弟
# @Site    : 博客地址:http://blog.csdn.net/lfdfhl
# @DESC    : while语句

'''
简单的while循环
'''
number=0
while number<5:
    print('当前i的值为:%i'%number)
    number=number+1

print(' = '*15)

'''
利用while循环从1累加至100
'''
index=1
total=0
while index<=100:
    total= total + index
    index= index + 1
print('0累加到100的结果是:total=%i'%total)

print(' = '*15)

'''
利用while循环打印*形图形
请注意:在调用print()时,end=''表示不换行
'''
j=0
while j<5:
    i=0
    while i<=j:
        print('*',end='')
        i=i+1
    print()
    j=j+1

print(' = '*15)

输出结果如下:

当前i的值为:0
当前i的值为:1
当前i的值为:2
当前i的值为:3
当前i的值为:4
 =  =  =  =  =  =  =  =  =  =  =  =  =  =  = 
0累加到100的结果是:total=5050
 =  =  =  =  =  =  =  =  =  =  =  =  =  =  = 
*
**
***
****
*****
 =  =  =  =  =  =  =  =  =  =  =  =  =  =  = 
相关文章
|
4月前
|
Python
python用户输入和while循环(四)
python用户输入和while循环(四)
47 1
|
4月前
|
Python
在Python中while循环
在Python中while循环
28 1
|
4月前
|
安全 Python
python用户输入和while循环(二)
python用户输入和while循环(二)
40 0
|
4月前
|
Python
python用户输入和while循环(一)
python用户输入和while循环(一)
34 0
|
4月前
|
存储 索引 Python
python用户输入和while循环(五)
python用户输入和while循环(五)
27 0
|
4月前
|
Python
python用户输入和while循环(三)
python用户输入和while循环(三)
34 0
|
4月前
|
存储 算法 索引
python用户输入和while循环(六)
python用户输入和while循环(六)
27 0
|
4月前
|
Python
【Python操作基础】——while语句用法和pass语句
【Python操作基础】——while语句用法和pass语句
|
4月前
|
大数据 Python
Python中while循环的嵌套应用详解
Python中while循环的嵌套应用详解
54 0
|
4月前
|
Python
Python while 循环
Python while 循环
36 0