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 = "\n") #等价于print()
num2 = 0
while num1<=5:
print(num1,end="_")
num2 = 0
while num2 <=7:
print(num2,end="-")
num2+=1
num1+=1
print(end = "\n") #等价于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-
相关推荐
哈嘿Blog 2020-10-26
明月清风精进不止 2020-07-05
PythonMaker 2020-07-05
xirongxudlut 2020-06-28
kkpiece 2020-06-16
qscool 2020-06-12
CloudXli 2020-06-11
vs00ASPNET 2020-06-09
Dimples 2020-06-08
kuoying 2020-06-07
JJandYY 2020-05-31
Wyt00 2020-05-30
liuyh 2020-04-03
CloudXli 2020-05-11
世樹 2020-05-11
bizercsdn 2020-05-10
sunnyhappy0 2020-05-09