请看如下示例:
# @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
= = = = = = = = = = = = = = =
*
**
***
****
*****
= = = = = = = = = = = = = = =