Solución reto #18 Python
Opened this issue · 0 comments
grisales54 commented
`def race(action: [], pista: str):
action_accept = ["run", "jump"]
# Validación de las acciones
if not all(a in action_accept for a in action):
raise ValueError(
"Las acciones solo pueden ser 'run' o 'jump'"
) # Raise detiene la ejecución del programa
pista_list = list(pista)
path = []
for i, j in zip(action, pista_list):
# Si el/a atleta hace "run" en "_" (suelo) y "jump" en "|" (valla) será correcto.
if i == "jump" and j == "|":
path.append("|")
if i == "run" and j == "_":
path.append("_")
# Si hace "run" en "|" (valla), se variará la pista por "/".
if i == "run" and j == "|":
path.append("/")
# Si hace "jump" en "_" (suelo), se variará la pista por "x".
if i == "jump" and j == "_":
path.append("x")
if ("x" or "/") in path:
return print(path)
else:
return print("Se ha superado la pista con exito")
Pruebas
try:
race(["run", "jump", "run", "run", "run", "jump", "run", "jump"], "|__|||")
race(["run", "jump", "pedro", "run", "run", "jump", "run", "jump"], "|__|||")
race(["run", "jump", "run", "run"], "_|__")
except ValueError as e:
print(f"Error: {e}")
`