11. Danger, Will Robinson!


#1



https://www.codecademy.com/courses/python-beginner-en-4XuFm/1/2?curriculum_id=4f89dab3d788890003000096#

Copy from output
('ROW: ', 1)
('COLUMN: ', 2)
You missed my battleship!
O O O O O
O O X O O
O O O O O
O O O O O
O O O O O
None

ERROR
Oops, try again. It looks like your game does not change the O to a capital X for an incorrect guess.


Pass to next level


from random import randint

#Print board function
def print_board(board):
    for row in board:
        print " ".join(row)

#Randomize ship position
def random_row(board):
    return randint(0, len(board) - 1)
def random_col(board):
    return randint(0, len(board[0]) - 1)
    
board = [] #Board list
for x in range(0, 5):#Filling the board with O
    board.append(["O"] * 5)
print_board(board) 

ship_row = random_row(board)
ship_col = random_col(board)

#User guess
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print("ROW: ", ship_row)
print ("COLUMN: ", ship_col)

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


#2

we use X to mark a wrong guess on the board, for which we use the coordinates entered by the user

you use the ship coordinates, use the user guess coordinates


#3

Stupid me,
Thank you!


#4