Error in lesson(Battleship!)

#1

Dear Sir,
Firstly i don't know what is the logic of this game and what kind of this it need to take and return the value . So, can you just esclate logic of this game , so i can understsnd completly . And i just follow the instructtion and i came untill here nad my code just struck with below are details.

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: "))``````

Error:

Oops, try again. Make sure your prompts are exactly as written in the instuctions. No changing the capitalization or using extra spaces!

#2

here:

``raw_input("Guess col: ")``

`Col` should have an uppercase first letter

#3

@stetim94
can you how this game supposed to be work and logic of this game also please.

#4

well, i hope you are familiar with battle ships? You try to sink (by guessing) the opponent ship, or in this case the computer ship, which is somewhere on the board (which we represent with a list in python)

#5

Dear Sir,
I just struck in this 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

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

Error:

Oops, try again. It looks like your game does not change the O to a capital X for an incorrect guess.

#6

this is a different exercise, you should have created a new topic

The error message is telling you what is wrong? We want to mark an incorrect guess by the user with a `X` on the board, you never do this

How do you think this can be achieved?

#7

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