码迷,mamicode.com
首页 > 编程语言 > 详细

【Python】Python 猜年龄的游戏

时间:2017-07-06 15:10:41      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:输入   range   用户   false   continue   exit   str   pre   span   

游戏规则:

  1. 允许用户最多尝试3次
  2. 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序
  3. 如何猜对了,就直接退出
 1 age=18
 2 count=True
 3 while count:
 4 
 5     for i in range(3):
 6         guess_age=int(input(你猜我的年龄是多大:))
 7         if guess_age < age:
 8             print(猜小了,往大里猜)
 9         elif guess_age > age:
10             print(猜大了,往小里猜)
11         else:
12             print(恭喜你,猜对了)
13             exit()
14     else:
15         ans=input(错误次数过多,是否继续:Y/n -->:)
16         if ans ==Y or ans == y:
17             continue
18         elif ans == N or  ans == n:
19             count = False
20         else:
21             print(输入错误,导致直接退出)
22             count = False

 

【Python】Python 猜年龄的游戏

标签:输入   range   用户   false   continue   exit   str   pre   span   

原文地址:http://www.cnblogs.com/yanglang/p/7126317.html

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