python while 循环-猜年龄-有次数限制
2018-04-03 16:27
363 查看
#python 2.7测试
#guess-猜年龄的游戏 -有次数限制
times = 1
age_of_tom = 55
print("You have 5 times to guess " )
while times < 6:
age = int(input("Guess the age:")) #python的输入全部为字符,需要类型转换
if age == age_of_tom:
print("Yes, You are right!")
break
elif age > age_of_tom:
print("No, Try a smaller value!")
else:
print("No, Try a bigger value!")
times = times + 1
else:
print("You have tried too many times")
#while循环结尾要保留空格
#guess-猜年龄的游戏 -有次数限制
times = 1
age_of_tom = 55
print("You have 5 times to guess " )
while times < 6:
age = int(input("Guess the age:")) #python的输入全部为字符,需要类型转换
if age == age_of_tom:
print("Yes, You are right!")
break
elif age > age_of_tom:
print("No, Try a smaller value!")
else:
print("No, Try a bigger value!")
times = times + 1
else:
print("You have tried too many times")
#while循环结尾要保留空格
相关文章推荐
- Python while循环-猜年龄-无次数限制
- python while循环-猜年龄-多次后提问是否继续
- python中限制循环次数
- 限制输入的次数用到while循环
- python while 循环
- Python--While循环语句
- python--while循环
- while循环猜年龄
- python循环语句,while及例子
- 以写代学:python while循环
- python的while循环
- 详解python基础之while循环及if判断
- Python学习笔记04-字典和用户输入和 while 循环
- python 循环while和for in简单实例
- python笔记-while循环中的知识点
- python中for、while循环、if嵌套的使用
- python之for循环、if循环、while循环
- 利用Python循环(包括while&for)各种打印九九乘法表的实例
- 限制递归次数,避免无限循环
- python入门(四):循环( for in 和 while)