# 11/19 - List assignment out of range

#1

EDIT: fixed. final code is below.

`````` #import random for position generation
from random import randint

board = [["  ","1","2","3","4","5"]]

for x in range(1, 6):
board.append([str(x) +":","O","O","O","O","O"])

#format board
def format_board(board):
for row in board:
print " ".join(row)

format_board(board)

#choose random location for ship
#row between 1 and length of the board - 1
def random_row(board):
return randint(1, len(board)-1)

#column between 1 and width of board - 1
def random_col(board):
return randint(1, len(board)-1)

#variables for ship location
ship_row = random_row(board)
ship_col = random_col(board)

#initiate game for four turns
for turn in range(4):
#print current turn
print "Turn", turn+1
#take a guess
guess_row = int((raw_input("Guess a row (1-5):")))
guess_col = int((raw_input("Guess a column (1-5):")))
if guess_row == ship_row and guess_col == ship_col:
board[guess_row][guess_col] = "X"
format_board(board)
print "Congratulations! You sank my battleship!"
break
elif board[guess_row][guess_col] == "o":
format_board(board)
print "You guessed that one already."
else:
print "You missed my battleship!"
if guess_row not in range(6) or guess_col not in range(6):
format_board(board)
print "Oops, that's not even in the ocean."
else:
board[guess_row][guess_col]="o"
format_board(board)
if turn == 3:
print "Game Over"``````