It's Not Cheating... Doesn't recognise str(ship_row) as answer


#1

It's Not Cheating - It's Debugging!

The error response is: "Oops, try again. Make sure to print out ship_row."

Interpreter should recognise str(ship_row) when checking the answer.

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)

guess_row = int(raw_input('Guess Row:'))
guess_col = int(raw_input('Guess Col:'))

print 'Ship Col: ' + str(ship_col)
print 'Ship Row: ' + str(ship_row)

#2

I think the interpreter is expecting the value in the int form even though it recognizes what str(ship_col) is. So, just do what I did:

print ship_col
print ship_row

#3

The way the validation is done, it doesn't appreciate your string casting. If you want to do it fancy, use the other method joining strings with integers:

print 'Ship Col:', ship_col
print 'Ship Row:', ship_row

#4

Interestingly, if I use the following code:

print 'Ship Col:' + str(ship_col)
print ship_row

I will be able to submit and pass the lesson. So the interpreter is also checking each element inconsistently!

But yes, thank you - that solved it.


#5