Hayden


#1



from random import randint

board = []

for x in range(0, 5):
#insert 1
    board.append(["O"] * 5)

def print_board(board):
#insert 1
    for row in board:
#insert 2
        print " ".join(row)

print_board(board)

def random_row(board):
#insert 1
    return randint(0, len(board) - 1)

def random_col(board):
#insert 1
    return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print ship_row
print ship_col

# Write your code below!
if guess_col == ship_col and guess_row == ship_row:
#insert 1
    print "Congratulations! You sank my battleship!"
else: 
#insert 1 for next 3 rows
    print "You missed my battleship!"
    board[guess_row][guess_col] = 'X'
    print print_board(board)

if guess_row not in range(5) or \
   guess_col not in range(5):
        print "Oops, that's not even in the ocean."


#3

hi

Heading

  • List item

#4

hi
.......................................................

  
    
      
        Welcome to Battleship!
      
      
        In this project you will build a simplified, one-player

version of the classic board game Battleship! In this version of the
game, there will be a single ship hidden in a random location on a 5x5
grid. The player will have 10 guesses to try to sink the ship.

To build this game we will use our knowledge of lists, conditionals
and functions in Python. When you're ready to get started, click run to
continue.

      
    
    
      
        Instructions
      
      
        Click Save & Submit Code to get started with Battleship!