11 and 12: I got the code to do exactly as required, but the site still give me error messages


#1

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

I ran my 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)

#print_board(board)

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)

#print ship_row
#print ship_col
#board[ship_row][ship_col]= "S"

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

if guess_row > 4 and guess_col > 4:
    print "Oops, that's not even in the ocean"
else:

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

Tested it with these values and got this as a display:

Guess Row: 100
Guess Col: 100

Oops, that's not even in the ocean
None

AND I RECEIVED THIS ERROR MESSAGE:

Oops, try again.
Make sure you print "Oops, that's not even in the ocean." if the user guesses a row or column that is off the board

The same thing happened with another previous section, where I got the game to behave exactly as prescribed, the printing out of the error message "You missed my battleship!" received the same kind of error which state I did not print out that error message.

I am going crazy.

Thanks for looking


#2

slightly different coding but i'm having the same problem/error message in lesson 12 telling me i need to print "Oops, etc" even though it does when i run the code and enter numbers higher than 5 in the console

if guess_row == ship_row:
    print "Congratulations! You sank my battleship!"
else:
    if guess_row not in range(5) or \
       guess_col not in range(5):
            print "Oops, that's not even in the ocean"
    else:
        print "You missed my battleship!"
        board[guess_row][guess_col] = "X"
        print_board(board)

#3

oh, just fixed it and it looks like you have the same problem as me: didn't put a period at the end of "Oops, that's not even in the ocean."


#4

man, they are really strict with the formatting of the output aren't they?

I still have problem remembering putting a ":" behind my def, for, if statements. These small syntax and details just going to bug me til I die.