PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Battleship guessing game!
This is a Exercise question from codecademy and is my first code in python.
The User needs to guess the position of the battleship to shoot it down in the ocean in terms of row and column of a 3x3 grid
User needs to enter the row and column respectively in seperate lines
Coded by-Amit Mathew
"""
from random import randint
board = []
for x in range(0, 3):
board.append(["O"] * 3)
def print_board(board):
for row in board:
print(" ".join(row))
print_board(board)
print("")
def random_row(board):
return randint(0, len(board) - 1)
def random_col(board):
return randint(0, len(board)- 1)
ship_row = random_row(board)
ship_col = random_col(board)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run