13/19 Not again


#1

This is my code:

if guess_row == ship_row and guess_col == ship_col:
  print "Congratulations! You sank my battleship!"
else:
    print "You missed my battleship!"
    board[guess_row][guess_col] = 'X'
print_board(board)

if guess_row not in range(5) or  guess_col not in range(5): 
  print "Oops, that's not even in the ocean."
  elif print board[guess_row][guess_col] == "X":
    print "You guessed that one already."

this is my error: File “python”, line 38
elif print board[guess_row][guess_col] == “X”:
^
SyntaxError: invalid syntax

what am I doing wrong here? Help me please.


#2

Please provide a link to the exact exercise you are on.


#3

Hi @emileae, look here:

and study the error:

Look at your elif statement… something isn’t right… why are we attempting to print in our statement?
Also, make sure your statements are indented correctly. (Look at @aquaphoenix17’s example as a reference.)

I think you can handle the rest (if you study the errors given) and carefully follow the instructions from the lesson. :wink:


#5

Hi @emileae,

The if statement in this exercise should be structured as follows:

if CONDITION:
    #Do Something
else:
    if CONDITION:
        #Do Something
    elif CONDITION:
        #Do Something
    else:
        #Do Something

Also, as mentioned by @intermediategamer,

print board[guess_row][guess_col] == "X"

is not a valid if / elif condition, as it is being evaluated and not run. Therefore, remove the print in the statement and it should suffice.

However, you must still make sure the entirety of your if statement follows the structure of the template I have shown you.


#6

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