Strange Error - Battleship (Hide...)


#1



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


When I add the code below to the section, it returns this error :
Make sure not to delete or modify the board!


However I don't see any issues with my code


# Add your code below!
def random_row(board):
    return randint(0, len(board)-1))

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


#2

Both of these need to be assigned to a variable.


#3

These are just functions calls.
Anyway, I tried to assign them to function calls and tried but it's returning the same error :frowning2:


#4

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)

# Add your code below!
def random_row(board):
    return randint(0, len(board)-1))

def random_col(board):
    return randint(0, len(board)-1))
    
a = random_row(board)
b = random_col(board)

#5

I used the same exact code as the first example and i got "Oops, try again. Did you create a function called random_row?"


#6

Yes, I did. You can see it in the code above:

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

I have no idea what's wrong with the code


#7

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

#8

think you've got an extra closing bracket?
should be randint(0, len(board) - 1)
rather than randinto(0, len(board)-1))


#9

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