码迷,mamicode.com
首页 > 编程语言 > 详细

python for循环基础实例

时间:2018-04-24 20:17:10      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:结束   input   trie   oop   off   got   loop   continue   SM   

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循环基础实例

标签:结束   input   trie   oop   off   got   loop   continue   SM   

原文地址:https://www.cnblogs.com/wzsx/p/8932948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!