Yes, these are zero indexed but when you guess 4,4 , it marks 5,5 as "x".then how do we correct it so that our guess_row, guess_col exactly is turned to "X"?
well, we would need to compensate for this difference
lets see, we could manipulate the list or the user input. Which do you think is easier to manipulate?
manipulating user input !
good, we want the user to input: 1, 2, 3, 4 or 5 and the list indexes are: 0, 1, 2, 3 and 4. See a pattern?
But any user expects to get 0 replaced with X at the same position which he has entered( I mean row,col) right! so why would a user change his way of input inorder to get actual replacement at 0. I tried
[guess_row - 1][guess_col - 1]. That gave me perfect result! but codecademy solution checker didn't approve the solution.
means: we will need to write code to manipulate the user input after the user inputted to compensate for this counting difference (human vs machine)
as we concluded, its easier to manipulate the user input.
so that is what you should do
yes! I understood.
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 - 1][guess_col - 1] = "X" print print_board(board)
Is this close enough to what you conveyed? But why does the codecademy verifier show that " you should not subtract 1" if it makes correct replacement.
i would do it earlier, directly when you prompt the user. Given in the next exercise you will add code to see if shot is even on board/in ocean. You will see in the next few exercises
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.