Battleship


#1

Is the placement of this elif statements is correct?

if guess_row == ship_row and guess_col == ship_col:
    print "Congratulations! You sank my battleship!"
    
elif board [guess_row][guess_col] == "X":
    print "You guessed that one already."
    
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 my battleship"
board[guess_row][guess_col] = "X"
print print_board(board)

Because when i again run the code and give the same coordinates it doesn't shows me the elif statement.
Or how can i get that elif statement?


#2

this are two questions. Is the placing correct? No.

you first build a handle to check if the shot is in the ocean:

if guess_row not in range(5) or \
    guess_col not in range(5):
        print "Oops, that's not even in the ocean."

the handle for checking if the user already guessed this one should be after the shot in the ocean handle.

If you run the code again, the board is empty again. In one of the next exercises you will build a loop, then you will see the already guessed handle to use.

We can also throw everything at once at the students, but this will confusing. Sometime you build something in the lesson which comes to live later


#3

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