文章目录
1.第一个while循环2.程序计数3.累加求和4.偶数求和5.break6.continue7.打印小星星8.print函数的结尾9.嵌套打印小星星10.九九乘法表11.转义字符
1.第一个while循环
i
= 1
while i
<= 3:
print("Hello Python")
i
+= 1
print("循环结束后,i = %d" % i
)
2.程序计数
i
= 0
while i
< 3:
print("Hello Python")
i
+= 1
print("循环结束后,i = %d" % i
)
3.累加求和
result
= 0
i
= 0
while i
<= 100:
print(i
)
result
+= i
i
+= 1
print("0~100之间的数字求和结果 = %d" % result
)
4.偶数求和
result
= 0
i
= 0
while i
<= 100:
if i
% 2 == 0:
print(i
)
result
+= i
i
+= 1
print("0~100之间的偶数累加结果 = %d" % result
)
5.break
i
= 0
while i
< 10:
if i
== 3:
break
print(i
)
i
+= 1
print("over")
6.continue
i
= 0
while i
< 10:
if i
== 3:
i
+= 1
continue
print(i
)
i
+= 1
7.打印小星星
row
= 1
while row
<= 5:
print("*" * row
)
row
+= 1
8.print函数的结尾
print("*", end
="---")
print("*")
9.嵌套打印小星星
row
= 1
while row
<= 5:
col
= 1
"""
1 1
2 2
3 3
4 4
5 5
"""
while col
<= row
:
print("*", end
="")
col
+= 1
print("")
row
+= 1
10.九九乘法表
row
= 1
while row
<= 9:
col
= 1
while col
<= row
:
print("%d * %d = %d" % (col
, row
, col
* row
), end
="\t")
col
+= 1
print("")
row
+= 1
11.转义字符
print("1\t2\t3")
print("10\t20\t30")
print("hello\n python")
print("hello\"hello")
转载请注明原文地址: https://yun.8miu.com/read-20914.html