11. Danger, Will Robinson (index problem)


#1

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"?


11. Danger, Will Robinson
#2

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?


#3

manipulating user input !


#4

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?


#5

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.


#6

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


#7

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.


#8

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


#10

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