鱼C论坛

 找回密码
 立即注册
查看: 616|回复: 3

[已解决]请问各位大神,我这段代码问题在哪里?

[复制链接]
发表于 2025-4-10 16:55:27 | 显示全部楼层 |阅读模式

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

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

x
import random
secret = random.randint(1,10)
times = 3

print("================================================================")

print("猜猜我现在心里想的数字是什么哦:",end = "")
while not input().isdigit():
    print("大哥,格式错误,请输入正确的数字:", end = "")
else:
    guess = 0
    while (times>0) and (guess!= secret):
        temp = input()
        guess = int(temp)
        times = times - 1
        if guess == secret:
            print("哇!你是我肚子里的蛔虫么^-^")
        else:
            if guess < secret:
                 print("小了!小了!")
            else:
                print("哥,大了,大了!")
            if times >0:
                print("再猜一次哦:", end = "")
            else:
                print("机会用完了T_T")
    else:
        print("游戏结束!")
最佳答案
2025-4-10 18:12:38
  1. import random
  2. secret = random.randint(1,10)
  3. times = 3

  4. print("================================================================")

  5. guess = 0

  6. while (times>0) and (guess!= secret):
  7.    
  8.     print("猜猜我现在心里想的数字是什么哦:",end = "")
  9.     temp = input()
  10.     while not temp.isdigit(): #输入部分要放到主循环里面
  11.         print("大哥,格式错误,请输入正确的数字:", end = "")
  12.         temp = input()
  13.     guess = int(temp)

  14.    
  15.     times = times - 1
  16.     if guess == secret:
  17.         print("哇!你是我肚子里的蛔虫么^-^")
  18.     else:
  19.         if guess < secret:
  20.              print("小了!小了!")
  21.         else:
  22.             print("哥,大了,大了!")
  23.         if times >0:
  24.             print("再猜一次哦:", end = "")
  25.         else:
  26.             print("机会用完了T_T")
  27. else:
  28.     print("游戏结束!")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2025-4-10 20:29:46 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-10-5 04:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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