9. It's Not Cheating—It's Debugging!


no error message

Guess Row: 5
Guess Col: 3

this is the output of the code. how is that 3 and 0 coming up?

Replace this line with your code. 
from random import randint

board = []

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

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

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

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

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

# Add your code below!
guess_row=int(raw_input("Guess Row: "))
guess_col=int(raw_input("Guess Col: "))
print ship_col
print ship_row


print ship_col
print ship_row

remove it :smiley:


how do i print the value then?


The reason that Codecademy has you do this ...

print ship_col
print ship_row

... is so that you can test your code by sometimes entering the actual ship location in response to the prompts and by sometimes entering another location. Those two statements are there only temporarily, and you can remove or comment them out later.

For now, place the statements in the following order so that, for testing purposes, you can see the ship location before entering the guesses ...

print ship_col
print ship_row
guess_row=int(raw_input("Guess Row: "))
guess_col=int(raw_input("Guess Col: "))


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.