首页 > 其他 > 详细

while循环

时间:2017-07-04 22:47:01      阅读:185      评论:0      收藏:0      [点我收藏+]

While循环    最简单的例子

Count = 0

While true:

       Print(“count:”,count)

       Count = count + 1  #count  +=1

 

列子1

Age_of_oldboy =56

Count = 0   计数

While true:

       If count ==3    执行3次退出

              Break

       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      计数

 

while列子2  优化版本

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      计数

Else:

       Print(“you have tried too many times..fuck off”)

while循环

原文:http://www.cnblogs.com/bjwwjun/p/7118880.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!