蓝绝

博客园 首页 新随笔 联系 订阅 管理

#for ...  in...  遍历循环

for i in range(1,6):         #数字遍历
    print(i)

for ch in 'Python':           # 字符串遍历
    print(ch)

#循环结构的 while 循环

a=1
while a<=5:    #放行条件
    print(a)   #分别换行输出 1,2,3,4,5
    a=a+1

#while 循环  中的 break与continue

 #break 中止当前循环

while True:  #True无条件放行
    answer=input('腿怎么样?能坚持吗?')
    if answer=='y':
        print('加油')
    else:
        print('不能,退赛')
        break                       #退出不再循环
F:\python3\python_3.8.3\python.exe E:/PycharmProjects/pythonProject/demon1/chap3/demo10.py
腿怎么样?能坚持吗?y
加油
腿怎么样?能坚持吗?n
不能,退赛

进程已结束,退出代码0

#continue  继续当前循环,从循环开头继续

circle=0
for i in range(1,11):
    answer=input('能跑吗?')
    if answer!='y':
        continue
    #circle=circle+1
    circle+=1

#print('一共跑了'+str(circle)+'圈')
print('一共跑了',circle,'')

 

posted on 2022-10-06 12:22  蓝绝  阅读(104)  评论(0)    收藏  举报