鱼C论坛

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

[已解决]关于鱼C第5课课后试一试问题0号

[复制链接]
发表于 2021-11-21 16:36:38 | 显示全部楼层 |阅读模式

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

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

x
import random
times = 3
secret = random.randint(1,10)
print('----我要打十个----')
# 这里先给guess赋值(赋一个绝对不等于secret的值)
guess = 0
# print()默认是打印完字符串会自动添加一个换行符,end=" "参数告诉print()用空格代替换行
# 嗯,小甲鱼觉得富有创意的你应该会尝试用 end="JJ"?
temp = input("不妨猜猜阿伟想在想的是哪个数字:",end=" ")#end引号里有空格             <-------------------            看这里看这里  官方报错说没有input的关键词参数
while type(temp) != type(1):#这种想法是因为type(1)会返回<class 'int'>,如果type(temp)返回结果一只说明输入是整数
    print("抱歉!格式不合法",end=" ")
    temp = imput("请输入一个整数:",end=" ")
最佳答案
2021-11-21 17:47:48
  1. #coding:gbk

  2. import random

  3. times , count = 3 , 0
  4. secret = random . randint(1,10)
  5. print('----我要打十个----')
  6. guess = 0
  7. while guess != secret and count < times :
  8.     temp = input("不妨猜猜阿伟想在想的是哪个数字:")
  9.     if not temp . isdigit():
  10.         print("抱歉!格式不合法")
  11.     else:
  12.         guess = int(temp)
  13.         if guess == secret:
  14.             print('恭喜你,猜对了!')
  15.             break
  16.         else:
  17.             if guess > secret:
  18.                 print('猜大了!')
  19.             else:
  20.                 print('猜小了!')
  21.             count += 1
  22.             if count < times:
  23.                 print('再猜一次')
  24. else:
  25.     print('很遗憾,' , times , '次机会用完了!')
  26. print('游戏结束。')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-11-21 17:47:48 | 显示全部楼层    本楼为最佳答案   
  1. #coding:gbk

  2. import random

  3. times , count = 3 , 0
  4. secret = random . randint(1,10)
  5. print('----我要打十个----')
  6. guess = 0
  7. while guess != secret and count < times :
  8.     temp = input("不妨猜猜阿伟想在想的是哪个数字:")
  9.     if not temp . isdigit():
  10.         print("抱歉!格式不合法")
  11.     else:
  12.         guess = int(temp)
  13.         if guess == secret:
  14.             print('恭喜你,猜对了!')
  15.             break
  16.         else:
  17.             if guess > secret:
  18.                 print('猜大了!')
  19.             else:
  20.                 print('猜小了!')
  21.             count += 1
  22.             if count < times:
  23.                 print('再猜一次')
  24. else:
  25.     print('很遗憾,' , times , '次机会用完了!')
  26. print('游戏结束。')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-24 23:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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