Danger, Will Robinson: My code is right but I keep an O instead of an X?


#1

Write your code below!

if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
else:
guest_row = "x"
guest_col = "x"
print "You missed my battleship!"
print_board(board)

Here is my code I think its correct but i keep getting the error: Oops, try again. It looks like your game does not change the O to a capital X for an incorrect guess.
Can someone tell me what i did wrong?


#2

You have guess_row and then guest_row. The same for the column variable.


#3

You have to make the change in the board[] list. Just the code guess_row = "X" is not making any change in board[] list.


#4

I'm having the same issue. Can't figure out why "X" is not printing. here's 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)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

print ship_row
print ship_col

Write your code below!

if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
else:
print "You missed my battleship!"
board[guess_row][guess_col] == "X"
print print_board(board)


#5

Nevermind, please disregard my question above. I figured it out. I changed

if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
else:
print "You missed my battleship!"
board[guess_row][guess_col] == "X"
print print_board(board)

to

if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
else:
print "You missed my battleship!"
board[guess_row][guess_col] = "X"
print print_board(board)

This worked for me.