社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

用PythonCharm编写一个猜年龄的小游戏!!!(10分钟)

Kinght_123 • 4 年前 • 289 次点击  
import random #把random模块调用出来
age = random.randint(10,25)#用rand.randint制造一个随机数表
count = 0
while count < 3:#共有三次机会
    n = int(input('Guess the age:'))#输入用户通过键盘敲打的数据
    if n > age:
        print('Try smaller,你还有%s次机会'%(2-count))
        count += 1
    elif n < age:
        print('Try bigger,你还有%s次机会'%(2 - count))
        count += 1
    else:
        print('Yes,you get it')
        break#结束循环
print(age)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/74465
 
289 次点击