12/19 Bad Aim: Is this a bug?


#1

Here's my code:

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 the battleship"

this gave me this result:

but also gave me this error:


#2

Might just be code academy being picky and wanting you to put a fullstop/period . after the word ocean

Seems to work fine other than that. (but I'm new to python also so :P)


#3

Thanks @benjnev I did just that and it let me go. I think they need to fix this.


#4

i am getting the some error but i dont understand what should i do.
can you expline the meaning of a fullstop\period?
thanks


#5

Basically a fullstop or period is just this symbol . put that after ocean before the " and it should let you pass.

The symbol you used after your word


#6

Got it done. I have to admit that it is quite annoying to be exactly the same on that output.
It has wasted half hour of my life. Gross


#7

I think they're so nit picky about very specific entry because that's part of coding. Syntax is just as picky as their required sentences.


#8

My problem was that I used " ` " symbol instead of " ' "
Lol... The only reason I found this error is because I got annoyed and copied the string from their instruction)


#9

does anyone know whats up with this, the not in range part of the code does not work for me so i cant get the "Oops! its not even in the ocean" message to print when i enter row and colum higher than range but it permits me to the different level.

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
board[guess_row][guess_col] = "X"
print print_board(board)

Write your code below!

if guess_col == ship_col and guess_row == ship_row:
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."
elif guess_row or guess_coll == "X":
print "You guessed that one already."
else:
print "you missed"


#10

I am stuck with this one. My code here:

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

Does someone know why it is not working?


#11

that same code is throwing an exception in my case.out of the ocean statement got printed but an exception:list assignment index out of range poped up