2017-11-07 17 views
-4

私はPythonとプログラミングの初心者です。私はカレッジ来るために頭を尽くすことを試みている夏期。私はこの初心者の本から学びたいと思っており、次のコードを私が書いているとおり正確に引用しています。スペースのインデントをどのように変更しようとしましたが、まだこのメッセージが表示されます。私はおそらくここに何かが不足していることを理解していますが、私はどのように進めるべきかについてのアドバイスを感謝します。IndentationErrorで新しく突っ込んだ:インデントされたブロックが予想されました

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) 
+1

あなたのインデントを修正してください(わからない場合は、googleが知っているでしょう) –

+0

あなたがする必要があるのはインデント 'ghost_door'です。ちょうどエラーのように言う – kstullich

+0

私はそれを理解するので、私は 'g'の前にインデント?申し訳ありませんが、私はまだレイアウトを理解しようとしています。 – Joseph

答えて

0

「while」ステートメントの後に、インタープリタが「...」を表示します。あなたは、次の行の先頭に4つの空白を入力してインデントを指定する必要があります。

+0

なぜ4つのスペース? – TZHX

+0

@TZHXこれはインデントに相当するためです。 – VortexYT

+0

1つのスペースがあります。またはタブ。 – TZHX

0

ライン上の既存のインデント現在

... ghost_door = randint(1,3) 

の前で[TAB]を押してインデントを追加し、あなたが持っている:

while feeling_brave: 
    ghost_door = randint(1, 3) 

あなたがのために、「ステートメント」を持っていませんインデントされたループになるので、インタプリタはそれを2つの連続したコマンドとして扱います。しかし、

while feeling_brave: 
    ghost_door = randint(1, 3) 

は、ループ実行中に2番目の行を実行するように通訳者に指示します。

+0

新しい行を保存するために、bsckticksを使用するのではなく、4つのスペースでコードの書式をインデントします。 – TZHX

+0

@TZHX新しい行を保存することはどういう意味ですか? – VortexYT

+0

あなたの答えを見ると、コードはあなたがそれを期待どおりに見えますか? – TZHX

関連する問題