码迷,mamicode.com
首页 > 其他好文 > 详细

for循环

时间:2017-07-04 23:22:41      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:bigger   bre   any   cout   range   --   ==   实现   例子   

For I in range(10)

       Print(“loop”,i)

 

 

For 循环 列子1

Age_of_oldboy =56

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”)

 

 

 

 

For循环 例子  只打10以内双数

For I in range(0,10,2):

       Print(“loop”,i)

列子 实现不退出继续循环

Age_of_oldboy =56

Count = 0   计数

While count < 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”)

       Count +=1      计数

       If count == 3:

              Coutine_confirm = input(“do you want to keep guessing..?”)

              If coutine_confirm !=’n’:

                     Count =0

 

 

循环套循环

For I in range(10):

       Print(’---------’,i)

       For j in range(10):

              Print(j)

              If j >5:

                     break

for循环

标签:bigger   bre   any   cout   range   --   ==   实现   例子   

原文地址:http://www.cnblogs.com/bjwwjun/p/7118882.html

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