我无法弄清楚我是否出错并且非常感谢帮助
the_number =random.randit(1, 9)
guess = int(input("take a guess: "))
while guess != the_number:
为什么说最后一行有语法错误。 (这不是完整的代码)
如果有帮助的话,这里是整个代码
import random
print("guess a number between 1 and 9")
guess =input()
guess =int(guess)
the_number = (random.randint(1, 9)
while guess != the_number:
if guess != the_number:
print("incorrect number guess again")
continue
else:
print("congratulations you have guessed the number was, " , the_number)
break
答案 0 :(得分:0)
你确定代码中有冒号给你一个错误吗?我可以在该行上产生语法错误的唯一方法是删除冒号,或用分号替换冒号,如下所示:
>>> while guess != the_number
或者这个:
>>> while guess != the_number;
做给出错误:
File "<stdin>", line 1
while guess != the_number
^
SyntaxError: invalid syntax
这个确切的错误恰好是Python文档中“语法错误”定义的示例错误 (Python 3或Python 2文档)。
P.S。欢迎来到Stackoverflow!下次你应该发布错误信息,你也会得到。如果你是一个初学者,这很好,谷歌搜索你的错误信息通常很有效。