I think this could be changed


#1

Hello! First of all I want to apologise for my bad english.

In the Python Battleship exercise we are first asked to use randint() with the len(board), in case we want to change the board size later.

09

But later on we are checking if guess_row and guess_col are in the range(5)

37

So now If we change our board size for for example 10, we won’t be able to choose any option outside that range(5) because it will be " Outside the ocean " right?

Well I think this range(5) could be changed to something like that:

if guess_row not in range(len(board)) or \
  guess_col not in range(len(board[0])):

What do you think about this?


#2

its possible, to makes it easier to change the board dimensions, but then you should change this as well:

for x in range(5):
  board.append(["O"] * 5)

to something like:

board_height = 5
board_width = 5

for x in range(board_height):
   board.append(["O"] * board_width)

in programming, everything is a balance. Trying to keep everything “open” so that everything can be easily changed is really good, but it cost additional time, which means additional cost.


#3

Ditto, there’s always a tradeoff with programming


#4

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