猜年龄小程序
Posted archerzon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了猜年龄小程序相关的知识,希望对你有一定的参考价值。
第一版,缺点只能猜一次。
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!")
以上是关于猜年龄小程序的主要内容,如果未能解决你的问题,请参考以下文章