13/19, Need help!


#1

Write your code below!

if guess_row==ship_row and guess_col==ship_col:
print "Congratulations! You sank my battleship!"
else:
if guess_row not in range(len(board)) or \
guess_col not in range(len(board)):
print "Oops, that's not even in the ocean."

else:
    print "You missed my battleship!";
    board[guess_row][guess_col]="X"

elif board[guess_row][guess_col]=='X':
    print "You guesses that one already"

print_board(board)

ERROR:
File "python", line 40
elif board[guess_row][guess_col]=='X':
^
SyntaxError: invalid syntax


#2

Hey, I think seeing all the code with correct intending would help quite a bit. I think this is likely a indentation or an issue with the else, if, and elif formatting.

I can confirm that the line that you're getting the error on doesn't seem to have a syntax issue. The error is likely in a line above that one.

The line after that; print "You guesses that one already"; does have a MINOR typo that won't stop the program from running. Just need to change 'guesses' to 'guessed' and to close the sentence with a period. Might not be an issue, but sometimes the validation testing looks for EXACT printing text.


#3

Yea, this is your issue right here, double check it.


#4

LOL, I totally missed that!!! Kind of stands out when you look at just that one line!


#5

Nah, it stands out when you become more familiar with the syntax. Try going back and forth between c++, c# or java back to python then you will have some issue.


#6

Thank codyroche and zeziba. I applied your suggestions but still have the same issue :confused:/
Can anyone give me the code so maybe I can figure out.


#7

Post what you have and let's take a gander!


#8

I just sort out the problem. Thank you so much zeziba :smile:


#9

Can you please post your code because I am having the same trouble and ca't seem to find the answer.


#10

For the time being put the code that gives syntax error as a comment. Later it will be sort out by itself.


#11

Hope this helps bud

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 print_board(board)

#12

so the point for me is that I should put elif below if statement and the last one is else..thanks


#13


#14