首页 > 其他 > 详细

4、while循环练习

时间:2018-01-20 21:06:07      阅读:187      评论:0      收藏:0      [点我收藏+]
#从简明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循环练习

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

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