14. Test Run "Oops, that's not even in the ocean."


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)

def random_row(board):
    return randint(0, len(board) - 1)

def random_col(board):
    return randint(0, len(board[0]) - 1)
print random_col(board)
print random_row(board)

ship_row = random_row(board)
ship_col = random_col(board)
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))

# Write your code below!
if guess_row == ship_row and guess_row == ship_row:
    print "Congratulations! You sank my battleship!"
    print "You missed my battleship!"
    board[guess_row][guess_col] = "X"
    if guess_row is not range(5) or guess_col is not range(5):
        print "Oops, that's not even in the ocean."
    elif board[guess_row][guess_col] == "X":
        print "You guessed that one already."

Every time the guess is wrong, it says "Oops, that's not even in the ocean."


Can you see a problem there?

That is testing if guess_row is not a range, not if it is in a range, use not in instead.


from random import randint

plateau = []

for x in range(0, 5):
plateau.append(["O"] * 5)

def afficher_plateau(plateau):
for ligne in plateau:
print " ".join(ligne)


def alea_ligne(plateau):
return randint(0, len(plateau) - 1)

def alea_col(plateau):
return randint(0, len(plateau[0]) - 1)

bateau_x = alea_ligne(plateau)
bateau_y = alea_col(plateau)
print bateau_x
print bateau_y

A partir d'ici tout le reste doit etre dans votre boucle for !

N'oubliez pas l'indentation !

tir_x = int(raw_input("Quelle ligne ?"))
tir_y = int(raw_input("Quelle colonne ?"))

if tir_x == bateau_x and tir_y == bateau_y:
print "Bravo ! Vous avez eu mon bateau !"
if (tir_x < 0 or tir_x > 4) or (tir_y < 0 or tir_y > 4):
print "Oups ! Vous devez viser l'ocean."
elif(plateau[tir_x ][tir_y ] == "X"):
print "Cette case est deja decouverte."
print "Dommage !"
plateau[tir_x ][tir_y ] = "X"
# Affichez tour+1 ici !
for tour in range(4):
tour = tour + 1
print affiche_plateau(plateau)


@elmabtoul, are you asking a question?


Why is not correct?

if guess_row != range(5) or guess_col != range(5):

Thank you!


Do you know what range(5) looks like? If you don't then you should print it and see.
You should also print your guess_row and guess_col and see if you think that they will ever be equal to range(5).