猜年龄小程序

时间:2018-08-13 21:52:23   收藏:0   阅读:215

第一版,缺点只能猜一次。

age_of_archerzon = 22

guess_age = int(input("guess age:"))

if guess_age == age_of_archerzon:
    print("yes,you got it!")
   break
elif guess_age > age_of_archerzon: print("think it smaller!") else: print("think it bigger!")

 

第二版,通过运用while循环实现了猜3次后退出。

 

优化版,将while循环改为for循环,

age_of_archerzon = 22

for i in range(3):
    guess_age = int(input("guess_age"))
    if guess_age == age_of_archerzon:
        print("yes,you got it!")
        break
    elif guess_age > age_of_archerzon:
        print("think it smaller!")
    else:
        print("think it bigger!")

 

原文:https://www.cnblogs.com/archerzon/p/9471095.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!