我是Python和编程的新手。我试图在夏季学期开始上大学。我试图从这本初学者的书中学习,它引用了下面的代码,正如我所说的那样...我试着改变空间缩进,但我仍然得到这个消息。我理解我可能在这里遗漏了一些东西,但我很欣赏有关如何继续的建议。
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)]
>>> # Ghost Game
... from random import randint
>>> print('Ghost Game')
Ghost Game
>>> feeling_brave = True
>>> score = 0
>>> while feeling_brave:
... ghost_door = randint(1, 3)
File "<stdin>", line 2
ghost_door = randint(1, 3)
^
IndentationError: expected an indented block
>>> ghost_door= randint(1, 3)
>>> while feeling_brave:
... ghost_door= randint(1, 3)
File "<stdin>", line 2
ghost_door= randint(1, 3)
^
IndentationError: expected an indented block
>>> while feeling_brave:
... ghost_door = randint(1, 3)
File "<stdin>", line 2
ghost_door = randint(1, 3)
^
IndentationError: expected an indented block
>>> while feeling_brave:
... ghost_door = randint(1,3)
File "<stdin>", line 2
ghost_door = randint(1,3)
^
IndentationError: expected an indented block
>>> while feeling_brave:
... ghost_door =randint(1,3)
File "<stdin>", line 2
ghost_door =randint(1,3)
答案 0 :(得分:0)
在“while”语句之后,口译员会显示“......”。您必须在下一行的开头键入四个空格来提供缩进。
答案 1 :(得分:0)
按行
上现有缩进前面的[TAB]添加缩进... ghost_door = randint(1,3)
目前,你有:
while feeling_brave:
ghost_door = randint(1, 3)
你还没有得到#34;陈述&#34;对于循环作为缩进,所以解释器将其视为两个连续的命令。但是,有
while feeling_brave:
ghost_door = randint(1, 3)
告诉解释器在循环运行时执行第二行。