FAQ: Learn Python - Battleship - Not Again!

This community-built FAQ covers the “Not Again!” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Not Again!:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

two questions:
1- in elif statement, we haven’t put the board[guess_row][guess_col] = “X” before the elif, so how we can check whether we guessed before.
2- I tried type numbers so that I get the “You guessed that one already.” message. but I get “You missed my battleship!” even if I typed the previous numbers in last Running the code.

1 Like

the program only remembers state while running, if you restart the program, the previous guesses are no longer there

this exercise is a step preparing you for the next exercise, where you make a loop (then you can test the multiple guesses)

3 Likes

I am having the same issue here, all I get is an error asking if I included the message “you guessed that already”
I have included that bit of code but I can’t check it as at present the code only does a single iteration…The lesson doesn’t allow for you to check the code so how are you meant to process?

the message printed (you guessed that already) needs to be an exact match, which i think is causing the problem, but i can’t verify, given you didn’t include any code

1 Like

Greetings, I have two questions and am on step 13:

  1. “You guessed that one already.” message appears on the first guess entry.
    I think folks have had a similar issue, but I can’t quite figure out why it’s happening on the initial guesses entry.

  2. To print the new ocean with “X” for the guess, I had to play around and subtract 1 (please see my code) - any idea why that is? I made it work and am not sure how/why.

Code

elif guess_row == guess_row and guess_col == guess_col:, this is always true? I mean, you are comparing the same variables, lets say i guess 3 and 4 i get:

elif 3 == 3 and 4 == 4

which is obviously true.

you need to check if something has already been guessed by checking if on that location on the board there is an X

as for point 2, lists are zero indexed based while humans start counting at one

1 Like

Thanks so much, I was able to fix my code and it works now. I didn’t realize I could write this line: board[guess_row-1][guess_col-1]== “X”

that is correct, if you want to subtract one (to compensate for zero indexed based lists) i would do it directly after prompting the user for input, then you don’t have to subtract one every time

1 Like

I have the same initial question as monson8564:
1- in elif statement, we haven’t put the board[guess_row][guess_col] = “X” before the elif, so how we can check whether we guessed before.

How can we check whether there’s an X at our location if we haven’t set the X yet?

if you have the same question, the same answer should be satisfying:

this exercise is a step preparing you for the next exercise, where you make a loop (then you can test the multiple guesses)

with a loop, you can guess the same coordinate multiple times, which is why this is step is necessary before you implement the loop

1 Like

How do we resolve this error : If a player guess is not an integer?

There are multiple ways, you could ask for permission (check if input is digit before converting) or ask for forgiveness (handle the exception)