Bad aim


#1

got error 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.

following is 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:
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 print_board(board)

please help

thanks in advance

`


#2

you miss an end point in Oops,that's not even in the ocean , try to add it and reply to me !


#3

still getting the same error

if guess_row==ship_row and guess_col==ship_col:
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 print_board(board)


#4

you don't need two "else" statements.

if():
if():
else:

#5

in this code you didn't add it !!
can you rewrite your code with indentation
also you can use elif here :


#6

change your second "else" statement to "elif"


#7

Thank you everyone. Its done


#8

how did u solve it I am getting the same error!


#9

i forgot to put . at the end of the sentence


#10

I have same mistake .But my mistake is print "Oops,that's not even in the ocean."
this line after "Oops," I did not give space .Look at that carefully . But when I print this line

print "Oops, that's not even in the ocean." Look at that I give space after comma so gives space . That' s it .If you don't understand then copy this line =>

print "Oops, that's not even in the ocean."


#11

thanks ! solved it :slight_smile:


#12

I have done everything rite but still Iam getting the same error