11 Danger Will Robinson!


Can someone help me with print_board(board). Im trying to understand how the whole thing work???


can someone spot whats wrong with my code pls?
if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sank my battleship!"
print "You missed my battleship"
board[guess_row][guess_col] = "x"


The words "work" and "wrong" don't carry much information and are therefore not very good for explaining what should be different about the behaviour of your program.
There's nothing to spot if it isn't known what it should do differently.

If you don't know what it should do differently, then you would need to provide a way for others to reproduce what you're doing, for that the whole code would be needed (make sure its formatting is kept intact or the code is ruined) - and a link to the exercise would also be needed so that there is something to compare your program to.


I'm trying to run this code and this error message pops up in the window :

SyntaxError: invalid syntax

here's the 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)


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!"
print "You missed my battleship!"
board[int(guess_row)[int(guess_col)] == "X"


That code will produce other error messages because its formatting is not intact. Details matter in code and so when shared one has to take care that it is exactly as it was written.
When there's a syntax error pointing at a line that is by itself valid, then the problem is probably above that line, something was probably left unfinished.


Somebody should say this...

Ionatan are you here to help people or preach them?

Your first message is so arrogant since it is clear to everyone he is asking help regarding 11 danger will robinson!

your second message is also redundant as it speaks about general things like attention but does not provide any meaningful direction.


I'm entirely unintrested in skipping ahead to how to edit a particular piece of code to get a green banner to show up

When I address the method that was used to attempt to solve a problem, that is sometimes interpreted as an assault on someone's person. Please re-read what I'm saying, that's not at all what is going on. I may be rather blunt, but that's something else entirely.


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