range (start, stop, step)
可以只有一个参数:range(5), 是指[0,1,2,3,4]
可以有两个参数:
range(1,5) = [1,2,3,4]
range(-1,5)=[-1,0,1,2,3,4]
while 循环
break 是指退出循环
while True:
if guess_age==age:
print ("you are right")
break
else:
...
...
continue 是指退出当次循环
num=1
while num<=10:
num+=1
if num%3==0:
continue
print (num)
实际输出:
2
4
5
7
8
10
11
while ... : ... else:
num=1
while num<=10:
num+=1
if num%3==0:
continue
print (num)
else:
print("this is else statement")
输出:
2
4
5
7
8
10
11
this is else statement
num=1
while num<=10:
num+=1
if num%3==0:
break
print (num)
输出:
2
作业输出九九表
while num1<=9:
num2=1
while num2<=num1:
print(num2,"*",num1,"=",num1*num2,end= " ")
num2+=1
num1+=1
print()
网友评论