-1
次のゲームを実行すると、「予期せぬインデント」というエラーが表示されますが、コードを見ると完全に正しいです。パイゲームの予期しないインデント
del evilGuy[-1]
でエラーが発生します。インデントは正しいですが、私はこのエラーが発生します。
EDIT
コードが少し変更されました。現在でも、予期しないインデントを示すdel evilGuy[-1]
にエラーが発生します。
def evilMove(evilGuy):
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)
del evilGuy[-1]
evilCoords.append(newCell['x'])
evilCoords.append(newCell['x'])
deadZones.append(evilCoords)
evilGuy.insert(0,newCell)
解決
エラーが関数evilMoveに '}' 欠けていました。 Solutiuonは以下のとおりです。
def evilMove(evilGuy):
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)} # Here It's missing '}'
del evilGuy[-1]
evilCoords.append(newCell['x'])
evilCoords.append(newCell['x'])
deadZones.append(evilCoords)
evilGuy.insert(0,newCell)
タブとスペースを混在させて使ったことがありますか? – xXliolauXx
私は@xXliolauXxが正しいと思います。これをテストするには、コード行をコピーします。スペースはドットを表示し、タブは行を表示します。 – GrvTyagi
@ xXliolauXx、いいえ、私はhavent混合タブとspaces.The上記のコードは私が自分のコードで持っているものです。 –