python for循环基础实例
Posted 无所住心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python for循环基础实例相关的知识,希望对你有一定的参考价值。
1、for循环竞猜年龄:
age_of_oldboy = 56
#guess_age = int(input("guess age:"))
count = 0
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("yes, you got it. ")
break #结束循环
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger!")
else:
print("you have tried too many times.. fuck off..")
2、for循环,continue跳出本次循环
for i in range(0,10):
if i < 3:
print("loop",i)
else:
continue #跳出本次循环,进入下次循环
print("hehe...")
以上是关于python for循环基础实例的主要内容,如果未能解决你的问题,请参考以下文章