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

4、while循环练习

时间:2018-01-20 21:25:46      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:als   练习   int   何事   ons   ttl   guess   div   higher   

#从简明Python搬来
number = 23
# 将23赋值给number的变量
running = True
# 在while语句运行前,将running变量设置为ture


while running:
    # 先检查变量running是否为ture,然后再运行相应的块
    guess = int(input(‘Enter an integer : ‘))

    if guess == number:
        print(‘Congratulations, you guessed it.‘)
        # 这将导致 while 循环中止
        running = False
    elif guess < number:
        print(‘No, it is a little higher than that.‘)
    else:
        print(‘No, it is a little lower than that.‘)
else:
    print(‘The while loop is over.‘)
# 在这里你可以做你想做的任何事
print(‘Done‘)

 

4、while循环练习

标签:als   练习   int   何事   ons   ttl   guess   div   higher   

原文地址:https://www.cnblogs.com/ludongjun/p/8321876.html

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