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'
I passed this without any bugs after I deleted the negative 1 (-1) from end of both “randint” lines.
(I just noticed many has used -1 there, for some reason. First I used that, but later I wanted to fix the code even that I passed the excercise)
So instead I added -1 to the end of quess_row and quess_col lines, like so:
guess_row = int(raw_input(“Guess Row:”)) -1
That means, that if user inputs number 5, it actually means index 6. But with “-1” in the end, it subtracts 1 from user input and therefor user input is inline with the indeces.
Use below code… it works correctly…
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’
Changed Into below
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)
Hi,
I followed the instruction you gave and passed this part , however I still don’t understand what ’ Set the list element at guess_row, guess_col to “X”.’ means and what is board[guess_row][guess_col] = ‘X’.
I truly don’t understand why should I put [guess_row] and [guess_col] behind board and why should I set it equal with ‘x’.
I don’t know where did it come from and what this code is used for.
Is there anyone can help me? Thank you very much.