Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución reto #18 Python #1359

Open
grisales54 opened this issue Sep 17, 2024 · 0 comments
Open

Solución reto #18 Python #1359

grisales54 opened this issue Sep 17, 2024 · 0 comments

Comments

@grisales54
Copy link

`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}")
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant