鱼C论坛

 找回密码
 立即注册
查看: 1390|回复: 4

[已解决]不懂为什么报错

[复制链接]
发表于 2017-9-28 19:10:40 | 显示全部楼层 |阅读模式

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

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

x
第五讲课后练习,动动手第0题,报错之后光标停在第10行的while的h后面,报错理由是invalid character in identifier,修改了之后还是一样的,求指教!!
最佳答案
2017-9-28 20:03:42
所有end = ''前面的逗号都是中文的,要改成英文的。26,27行缩进要左移。
  1. import random

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

  4. guess = 0
  5. print("猜数字:", end = '')

  6. while(guess != secret) and (times > 0):
  7.     temp = input()

  8.     if temp.isdigit():
  9.         guess = int(temp)
  10.         if guess == secret:
  11.             print("猜对了")
  12.             print("哼")
  13.         else:
  14.             if guess > secret:
  15.                 print("大了")
  16.             else:
  17.                 print("小了")
  18.             if times > 1:
  19.                 print("再试一次吧:", end = '')
  20.             else:
  21.                 print("没机会了")
  22.     else:
  23.         print("抱歉,您的输入有误,请输入一个整数:", end = '')

  24.         times = times - 1
  25. print("游戏结束")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-9-28 19:15:21 | 显示全部楼层
把你的程序发上来
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-9-28 19:31:10 | 显示全部楼层
  1. import random

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

  4. guess = 0
  5. print("猜数字:",end = '')

  6. while(guess != secret) and (times > 0):
  7.     temp = input()

  8.     if temp.isdigit():
  9.         guess = int(temp)
  10.         if guess == secret:
  11.             print("猜对了")
  12.             print("哼")
  13.         else:
  14.             if guess > secret:
  15.                 print("大了")
  16.             else:
  17.                 print("小了")
  18.             if times > 1:
  19.                 print("再试一次吧:",end = '')
  20.             else:
  21.                 print("没机会了")
  22.         else:
  23.             print("抱歉,您的输入有误,请输入一个整数:",end = '')

  24.         times = times - 1
  25. print("游戏结束")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-9-28 20:03:42 | 显示全部楼层    本楼为最佳答案   
所有end = ''前面的逗号都是中文的,要改成英文的。26,27行缩进要左移。
  1. import random

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

  4. guess = 0
  5. print("猜数字:", end = '')

  6. while(guess != secret) and (times > 0):
  7.     temp = input()

  8.     if temp.isdigit():
  9.         guess = int(temp)
  10.         if guess == secret:
  11.             print("猜对了")
  12.             print("哼")
  13.         else:
  14.             if guess > secret:
  15.                 print("大了")
  16.             else:
  17.                 print("小了")
  18.             if times > 1:
  19.                 print("再试一次吧:", end = '')
  20.             else:
  21.                 print("没机会了")
  22.     else:
  23.         print("抱歉,您的输入有误,请输入一个整数:", end = '')

  24.         times = times - 1
  25. print("游戏结束")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-9-28 21:33:47 | 显示全部楼层

终于对了!!谢谢!!!!!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-10-4 03:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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