python全栈 S3--9day--while语句以及练习题(9)
一、循环
死循环
while 1 == 1: print ("你好")
无限循环输出当前时间
import time while 2 == 2: print("ok",time.time())
循环的定义:如果符合条件的话。无限循环执行代码块内容
如果想要终止死循环的话,可以添加一些条件
count = 0 while count<10: print ("你好") count+=1 print(123)
练习题:
1、使用while循环输出123456 8970
count=0 while count < 10: count+=1 if count==7: continue else: print (count)
2、求1-100所有数的和
jay=1 jake=0 while jay<100: jake =jake+jay jay+=1 print (jake)
3、输出1-100所有的基数
jay =1 while jay < 100: temp =jay % 2 if temp == 0: pass else: print (jay) jay+=1
4、输出1-100中所有的偶数
conut = 1 while conut < 100: jay = conut % 2 if jay == 0: print(conut) else: pass conut += 1
补充:
等于:==
不等于:!=
浙公网安备 33010602011771号