Quick question


#1
from random import randint
board = []

for x in range(5):
    board.append("O" * 5)
def print_board(lst):
    for item in lst:
        print "  ".join(item)
print "Welcome to Battleship game!"
print_board(board)

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)
board[ship_row][ship_col] = "X"

I just want to print the letter x in my board.

This is the error that I get - 'str' object does not support item assignment


#2

There is your issue, they are trying to have to edit a string. Which by the way is an immutable in python.


#3

@lukasvisinskis

I should mention that you can change your generator to,

for row in range(5):
    board.append(['O'] * 5)

It works the same way but you do not have a string to change.