Battleship - random_row not defined


#1

Dont understand whats wrong with the code below:
I get the error message random_row not defined evenif the function random_row is defined before it:)

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)
print_board(board)

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

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

randow_row(board)
random_col(board)


#2

Btw, the indents didnt come up in my post!


#3

Your missing the zero index boardd[0] in both your functions,
[quote="sar_code, post:1, topic:61381"]

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

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


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

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

#And you didn't name your variables like this
ship_row = random_row(board)
ship_col = random_col(board)

#4

Read the pinned topic on the Latest page for help with formatting code samples.

https://discuss.codecademy.com/


#5

Thank you! It worked:)


#6

Thanks for the link!


#7

You're welcome :smile:


#8

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