鱼C论坛

 找回密码
 立即注册
查看: 1166|回复: 1

[已解决]代码有问题吗?

[复制链接]
发表于 2022-5-2 22:11:15 | 显示全部楼层 |阅读模式

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

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

x
  1. #p3_85.py
  2. import easygui as eg
  3. import random as rdm

  4. try:
  5.     eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
  6.     答案 = rdm.randint(1,100)
  7.     回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-100):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 100)
  8.     while 回答!= 答案:
  9.         if 回答 == 答案:
  10.             eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
  11.             break
  12.         else:
  13.             if 回答 > 答案:
  14.                 eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)
  15.             if 回答 < 答案:
  16.                 eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)

  17.     eg.msgbox(msg = '游戏结束!' , title = '结束' , ok_button = '确定')
  18. except ValueError as cut:
  19.     eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
复制代码

为啥要不一直说大了,要不就是小了?
最佳答案
2022-5-2 22:14:52
重新猜之后得赋值,不然回答一直不变
  1. #p3_85.py
  2. import easygui as eg
  3. import random as rdm

  4. try:
  5.     eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
  6.     答案 = rdm.randint(1,100)
  7.     回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-100):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 100)
  8.     while 回答!= 答案:
  9.         if 回答 == 答案:
  10.             eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
  11.             break
  12.         else:
  13.             if 回答 > 答案:
  14.                 回答 = eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)                  # 注意这里
  15.             if 回答 < 答案:
  16.                 回答 = eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)                  # 注意这里

  17.     eg.msgbox(msg = '游戏结束!' , title = '结束' , ok_button = '确定')
  18. except ValueError as cut:
  19.     eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-5-2 22:14:52 | 显示全部楼层    本楼为最佳答案   
重新猜之后得赋值,不然回答一直不变
  1. #p3_85.py
  2. import easygui as eg
  3. import random as rdm

  4. try:
  5.     eg.msgbox(msg = '欢迎进入猜数字小游戏!' , title = '猜数字小游戏' , ok_button = '继续')
  6.     答案 = rdm.randint(1,100)
  7.     回答 = eg.integerbox(msg = '猜一猜作者心里想的是什么数字(1-100):' , title = '猜数字小游戏' , lowerbound = 1 , upperbound = 100)
  8.     while 回答!= 答案:
  9.         if 回答 == 答案:
  10.             eg.msgbox(msg = '回答正确!' , title = '恭喜您,猜中了!' , ok_button = '确定')
  11.             break
  12.         else:
  13.             if 回答 > 答案:
  14.                 回答 = eg.integerbox(msg = '嘿,大啦大啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)                  # 注意这里
  15.             if 回答 < 答案:
  16.                 回答 = eg.integerbox(msg = '嘿,小啦小啦!请重新输入:' , title = '很遗憾,猜错啦!' , lowerbound = 1 , upperbound = 100)                  # 注意这里

  17.     eg.msgbox(msg = '游戏结束!' , title = '结束' , ok_button = '确定')
  18. except ValueError as cut:
  19.     eg.msgbox(msg = ('类型出错啦T_T\n错误原因是:' + cut) , title = '错误' , ok_button = '确定')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-29 01:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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