【发布时间】:2018-04-20 07:00:57
【问题描述】:
我是 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)
【问题讨论】:
-
听起来不言自明,修复你的缩进(如果你不知道怎么做,谷歌会知道)
-
所有你需要做的就是缩进
ghost_door。就像错误所说的那样 -
那么,据我所知,我在“g”之前缩进了吗?对不起,我还在努力理解布局..
-
@Joseph 这可能会对您有所帮助——这是 python 代码的样式指南python.org/dev/peps/pep-0008
-
非常感谢英镑。
标签: python python-3.x error-handling indentation