10/19 You Win ! issue


I ran the below code, it is executing fine but after giving the guess numbers, it is not printing what it wants.
I am not able to guess the numbers to print the result phrase.
help me on this ASAP..!!

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 "Congratualtions! you sank my battleship!"


It seems to work fine when I run it. It prints out the board, asks me to guess the row and column and then prints out where the ship is hiding. What is it not doing for you?


That execrise want to print the "Congratualtions! you sank my battleship!"
But I am unable to print it,.it seems some thing is wrong
My inputs:
Guess row: 3
Guess col: 4
but not that phrase,.. what is wrong code or my entries,.?


Move the print statements that show where the ship is above where you guess that way you can see where the ship is before you guess. Like so:

ship_row = random_row(board)
ship_col = random_col(board)

print ship_row
print ship_col

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


It worked,..
and one more part where i missed it is I didn't typed the phrase that given in instructions...
Thanks..for your help and quick response


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