2016-06-21 24 views
0

ここで私のコードは実際には無限ループを使用してint値をスキャンして比較します。 「:インデントブロックを期待indentationError」IndentationError:Pythonでインデントされたブロックのエラーが発生する可能性があります。可変スキャン時にエラーが発生します。

running = True 
while running: 
guess = int(input('Enter an integer : ')) 
if guess == number: 
print 'Congratulations, you guessed it.' 
# this causes the while loop to stop 
running = False 
elif guess < number: 
print 'No, it is a little higher than that.' 
else: 
print 'No, it is a little lower than that.' 
else: 
print 'The while loop is over.' 
# Do anything else you want to do here 
print 'Done' 
+1

エラーがすべて表示されます。インデントを修正します。 – Julien

+0

Pythonはインデントを使用してコードブロックをマークします。いくつかの基本的なPythonチュートリアルを見てください。詳細については、あなたのために説明します。 –

+0

あなたの[pythonの基礎](https://docs.python.org/2/tutorial/appetite.html)を見直さなければならないと思います。 –

答えて

0

多くの言語は、条件式の枝、関数、クラスをカプセル化するために括弧を使用するなどPythonは空白を使用していないが、それは私に関するエラーを与える動作しません。代わりにこれを行う。コードの正しい書式は次のとおりです。

running = True 
while running: 
    guess = int(input('Enter an integer : ')) 
    if guess == number: 
     print 'Congratulations, you guessed it.' 
     # this causes the while loop to stop 
     running = False 
    elif guess < number: 
     print 'No, it is a little higher than that.' 
    else: 
     print 'No, it is a little lower than that.' 
else: 
    print 'The while loop is over.' 

# Do anything else you want to do here 
print 'Done' 
+0

あなたはそれが完璧に仕事です。 –

+0

問題ないです、喜んで助けてください!これで問題が解決した場合は、投票矢印の横にあるチェックボックスをクリックして回答を受け入れ、解決済みと表示してください。 – Will

関連する問題