Need Help With Syntax


#1

https://www.codecademy.com/en/courses/learn-python/lessons/battleship/exercises/play-it-sam

I’m trying to write my code so that a player has 4 guesses before losing the game. I’ve added the “For” loop like the lesson says I should but I’m having problems with indentions and formatting. I’ve gone through line by line trying to fix my code but I just seem to be stuck. Currently, I’ve been seeing the error on line 39 about improper syntax. I would appreciate any help :slight_smile:

for turn in range(4):
	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!"   
	else:
  		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." )
  	else:
    			print "You missed my battleship!"
    			board[guess_row][guess_col] = "X"
  				print_board(board)
  # print turn + 1 here
  print "Turn", turn+1




#2

it looks like the else above “you missed my battleship” needs to be indented to match the elif board line. also it looks like the last print line is slightly off. its indentation doesn’t match anything


#3

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