James_ZhouSH 2021-10-07 09:54 采纳率: 100%
浏览 43
已结题

我做了一个Python的小游戏猜数字,但是猜对了,他不会有任何提示

# This is a guess the number game.
import random
secretNumber = random.randint(1,20)
print(' I am thinking of a number between 1 and 20. ')

#Ask the player to guess 20 times
for guessesTaken in range(1, 20):
      print( 'Take a guess.' )
      guess = int(input())
    
      if guess < secretNumber:
           print( ' Your guess is too low.' )
      elif guess > secretNumber:
           print(' Your guess is too high.' )
      else:
           break # This condition is the correct guess!

if guess == secretNumber:
     print( ' Good job! You guessed my number in ' + str(guessesTaken) + ' guesses! ')
else: 
     print( ' Nope.  The number I was thinking of was ' + str(secretnumber))

img

  • 写回答

1条回答 默认 最新

  • 微笑的菜鸟 2021-10-07 11:27
    关注

    代码没问题,看最后的if else一定会有提示输出的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月29日
  • 已采纳回答 10月21日
  • 创建了问题 10月7日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改