Excellent! Now, let’s hide our battleship in a random location on the board.
Since we have a 2-dimensional list, we’ll use two variables to store the ship’s location,
from random import randint coin = randint(0, 1) dice = randint(1, 6)
- In the above example, we first import the
randint(low, high)function from the
- Then, we generate either zero or one and store it in
- Finally, we generate a number from one to six inclusive.
Let’s generate a
random_col from zero to four!
Define two new functions,
random_col, that each take
board_in as input.
These functions should
return a random row index and a random column index from your board, respectively. Use
randint(0, len(board_in) - 1).
Call each function on