Help with battleship coordinates


#1

whenever I enter the coordinates for attacking the ship it appears at another coordinate +1 of the one i entered. for example, if i were to enter (1, 1), the “X” will appear at (2, 2). and if i enter (5, 5) it would say that it is not part of the ocean. I get this has something to do with indexes but I don’t know which line is causing this to happen


#2

Because Python lists are zero-indexed, the values must be within range(5) (the length of the list) which means in the following list…

[ 0, 1, 2, 3, 4 ]

The coordinates, [0, 0] will be the first row, first column. [4, 4] will be the last row and last column.


#3

so there is no way for me to make it start at 1?


#4

There is a way, but for the exercise we should put that desire aside until the track is complete. Stick to the instructions and experiment when you get to the end.

guess_row = int(raw_input("Enter a row: ")) - 1

Now you can enter 1…5 but the program sees 0…4.

Note

Be sure to tell the user what the expected inputs are…

guess_row = int(raw_input("Enter a row (1..5): ")) - 1

#5

oh nice! thanks so much!


#6

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