A real win


  1. A real win

File "python", line 36
SyntaxError: 'break' outside loop

I don't know how to manage to pass this part. My code seems to be fine but no matter how I put the break at line 36, it always have a mistake.

import random

tablero = []

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

def print_tablero(tablero):
  for fila in tablero:
    print " ".join(fila)

print "Juguemos a la batalla naval!"

def fila_aleatoria(tablero):
  return random.randint(0,len(tablero)-1)

def columna_aleatoria(tablero):
  return random.randint(0,len(tablero[0])-1)

barco_fila = fila_aleatoria(tablero)
barco_columna = columna_aleatoria(tablero)
print barco_fila
print barco_columna

#¡De acá en adelante todo debería ir en tu ciclo for!
#¡Asegurate de indentar!
turn = 0
for turn in range (4):
    adivina_fila = input("Adivina fila: ")
    adivina_columna = input("Adivina columna: ")

if adivina_fila == barco_fila and adivina_columna == barco_columna:
    print "Felicitaciones! Hundiste mi barco!"

if (adivina_fila < 0 or adivina_fila > 4) or (adivina_columna < 0 or adivina_columna > 4):
    print "Huy, eso ni siquiera esta en el oceano."
elif(tablero[adivina_fila][adivina_columna] == "X"):
    print "Ya dijiste esa."
  	print "No tocaste mi barco!"
  	tablero[adivina_fila][adivina_columna] = "X"
  # ¡Mostrá (turno + 1) acá!
print "Turn", turn + 1
if turn == 3:
    print"Fin del juego"


If it is not passing, then it is not fine. That it is raising an interpreter exception is definitely not fine. It points to a scope issue. The break might be at a different indentation than is expected (by the interpreter).

On closer inspection we see that is the cause.


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