【发布时间】:2016-07-18 10:53:16
【问题描述】:
我正在尝试制作一个基本的数字猜谜游戏,因为我刚刚开始编码。我不明白我做错了什么。我试着在这里的论坛上寻找,但我没有找到答案。如果有人能告诉我我做错了什么,我将不胜感激!
import random
num = random.randint(1, 10)
while true:
guess = int(input("Guess a number between 1 and 10: "))
if guess is == num
print("you got it!")
break
else:
print("try again!")
错误:
break
^
IndentationError: unexpected indent
【问题讨论】:
-
clue
if guess is == num也没有意义,如果您收到错误然后包含错误。您可能希望if guess == num:注意删除is并添加冒号: -
谢谢你我修正了那个错误。你介意解释为什么结肠是必要的吗?我现在有一个不同的错误:break ^ IndentationError: unexpected indent
-
咨询docs
-
好的,感谢您的帮助。
标签: python