Python


#1

Hello,

I need help with the battleship section of python. I am in the 12th part and I am having a hard time with this. So hear are the codes that I tried that didn't work with me.

First one was:

else:
if guess_col not in range(5) or guess_row not in range(5):
print "Oops, that's not even in the ocean."
elif board guess_row, guess_col == "X":
print "You guessed that one already."

Second one was:
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!"
guess_row, guess_col == "X"
print_board(board)

Pleas help me!


#2

how is the indention of your code? please format your code, so we can see it

here:

elif board guess_row, guess_col == "X":

board is a list, guess_row and guess_col are indexes to retrieve value. to use indexes with lists, use square brackets


#3

Do you still use the else:


#4

yes, you do. I wast just saying where you went wrong

Please post your code using format


#5

I add elif board guess_row, guess_col == "X": and it still didn't work.


#6

you already had it? You have to modify it. board is a list, so you need the following syntax to update:

yourList[indexOne][indexTwo] = "new value"

list can be accessed by index using square brackets


#7

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


#8

#9

https://discuss.codecademy.com/t/python/96057/6

What do I need for the else statment.


#10

Please improve the quality of your question:

code
error message
explain what you do understand and what you don't

use markup for the code:

so indent shows