鱼C论坛

 找回密码
 立即注册
查看: 2065|回复: 0

[作品展示] Python猜数字小游戏(新手上路)

[复制链接]
发表于 2018-7-28 17:10:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 子沙 于 2018-7-28 17:13 编辑
  1. import random
  2. secret=random.randrange(1,101)
  3. print('The integer is between 1 and 100.')
  4. times=int(input('How many times do you want to guess?\n'))
  5. guess=int(input('Enter a integer:'))
  6. i=1   
  7. while i<times:
  8.     if guess==secret:
  9.         if i==1:
  10.             print('You only use',i,'chance.')
  11.         else:
  12.             print('You only use',i,'chances.')
  13.         i=times
  14.     else:
  15.         if guess<secret:
  16.             print('No, it is a little higher than that.(',i,'/',times,')')
  17.         else:
  18.             print('No, it is a little lower than that.(',i,'/',times,')')
  19.         guess=int(input('Enter a integer:'))
  20.         i=i+1
  21. if guess==secret:
  22.     print('Congratulations, you guessed it.')
  23.     print('Game is over.')
  24. else:
  25.     print('Sorry, you fail the game.(',i,'/',times,')')
  26.     print('Game is over. Thanks')
复制代码

评分

参与人数 1鱼币 +2 收起 理由
青春奋斗 + 2

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-21 20:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表