python学习20200509while循环语句
Posted wangyunpeng888888
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python学习20200509while循环语句相关的知识,希望对你有一定的参考价值。
while循环语句
age = 50
guss_age = int(input("请输入您猜测的年龄:"))
while guss_age !=age:
if guss_age > age:
print("您猜大了:请重试!")
else:
print("您猜小了:请重试!")
guss_age = int(input("请输入您猜测的年龄:"))
guss_age = int(input("请输入您猜测的年龄:"))
while guss_age !=age:
if guss_age > age:
print("您猜大了:请重试!")
else:
print("您猜小了:请重试!")
guss_age = int(input("请输入您猜测的年龄:"))
print("您猜对了!")
while 条件:
.....
else: #只有while语句里有break,else 语句才不会执行
.....
break 终止
num =0
while num <10:
print(num)
num = num +1
break
while num <10:
print(num)
num = num +1
break
continue跳出当次循环,继续从头开始
num = 1
while num <=10:
while num <=10:
num = num +1
if num == 3:
continue
print(num)
if num == 3:
continue
print(num)
结果:
2
4
5
6
7
8
9
10
11
4
5
6
7
8
9
10
11
三行语句不换行
print("hallo word")
print("hallo word")
print("hallo word")
print("hallo word",end ="___")
print("hallo word",end ="___")
print("hallo word",end ="___")
num1 = 0
num2 = 0
while num1<=5:
print(num1,end="_")
num2 = 0
while num2 <=7:
print(num2,end="-")
num2+=1
num1+=1
print(end = " ") #等价于print()
num2 = 0
while num1<=5:
print(num1,end="_")
num2 = 0
while num2 <=7:
print(num2,end="-")
num2+=1
num1+=1
print(end = " ") #等价于print()
结果:
0_0-1-2-3-4-5-6-7-
1_0-1-2-3-4-5-6-7-
2_0-1-2-3-4-5-6-7-
3_0-1-2-3-4-5-6-7-
4_0-1-2-3-4-5-6-7-
5_0-1-2-3-4-5-6-7-
1_0-1-2-3-4-5-6-7-
2_0-1-2-3-4-5-6-7-
3_0-1-2-3-4-5-6-7-
4_0-1-2-3-4-5-6-7-
5_0-1-2-3-4-5-6-7-
以上是关于python学习20200509while循环语句的主要内容,如果未能解决你的问题,请参考以下文章