12. Bad Aim


#1


Stuck with bad aim...


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:
    if guess_row not in range(len(board)) or guess_col not in range(len(board)):
        print "Opps, that's not even in the ocean."
    if ((guess_row != ship_row) or (guess_col != ship_col)) and \
        (guess_row in range(len(board)))and(guess_col in range(len(board))):
        print "You missed my battleship!"

def replace_chars(s):
    return s.replace('O', 'X')



**

## Help please...

**

Cann't figure out what is wrong... my code works but cannt progress as i get this 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.

<What do you expect to happen instead?>


<do not remove the three backticks below>
```python


Replace this line with your code. 



#2

if (guess_row == ship_row) and (guess_col == ship_col):
    print "Congratulations! You sank my battleship!"
else:
    if guess_row not in range(len(board)) or guess_col not in range(len(board)):
        print "Opps, that's not even in the ocean." #You spelled oops wrong
    if ((guess_row != ship_row) or (guess_col != ship_col)) and \
        (guess_row in range(len(board)))and(guess_col in range(len(board))): #This can just be else:
        print "You missed my battleship!"

#3

wow

thanks! I cann't believe that it was just the miss spelling of Oops... or should I say Opps!


#4

I DID THE SAME THING! Silly o willy


#5

I think the instructions were very much ambiguous and thats why you got confused but if you follow the standard Boolean expression structure, you shouldn't be far off to the next lesson


#6

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