12. bad aim


#1

Hello, gives an error message (Traceback (most recent call last):
File "python", line 33, in
IndexError: list index out of range )
what's the problem, thanks for the tip (sorry i have bad english)

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

12. Bad Aim
#2

okay, so this is the code you start the exercise with:

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)

then the first instruction is:
Add a new if: statement that is nested under the else.

so we want to nest if under else:

if guess_row == ship_row and guess_col == ship_col:
    print ("Congratulations! You sank my battleship!")
else:
    if:
    print("You missed my battleship!")
    board[guess_row][guess_col] = "X"
print_board(board)

see where i added the if? that is what the instructions tell you. Now please read the rest of the instructions again

Also, this is python2, don't use parentheses when using print


#3

big thanks, I use google tranlater and i can not always understand what they want from me )


#4

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