Play It, Sam indent error


For some reason, I’m receiving an indentation error. I feel like I’ve tried everything, and I think it should be right but it’s not. Error message:
IndentationError: unindent does not match any outer indentation level
local area:
edit: on my screen there is an indent before print. Why isn’t it there on this message? I typed it by backspacing so it was on the same line as the if statement then pressing enter

for turn in range(4):
	print turn+1

	if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sunk my battleship!"

screen shot:
20 AM
Thanks in advance!


I literally just finished this and it took me over an hour to figure out the exact indentation problem you’re having. My issues were later on in the code with the if/elif/else statements, but it was still the same issue. What finally did it for me was going back and making sure that, instead of hitting “Tab” to indent, I hit the space bar twice. Honestly don’t know if that makes a difference at all, but I combed over the code for hella long until I couldn’t find any other solution, and just tried that, and it worked. Also, make sure that the error message is referring to that part of the code specifically so that you’re not trying to fix something that’s not broken.

Here is the code I used for that part:

for turn in range(4):
  print "Turn", turn + 1
  guess_row = int(raw_input("Guess Row: "))
  guess_col = int(raw_input("Guess Col: "))
  if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"
    if guess_row not in range(5) or guess_col not in range(5):
      print "Oops, that's not even in the ocean."
    elif board[guess_row][guess_col] == "X":
      print( "You guessed that one already." )
      print "You missed my battleship!"
      board[guess_row][guess_col] = "X"

Hope that helps, good luck!


Thanks! I tried that, and it didn’t work, but for some reason after I reset the exercise it worked fine, so I guess there was just some kind of glitch going on


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.