From 8da46e403e43448437a4a6e88a16dd3d27898685 Mon Sep 17 00:00:00 2001 From: javier <203809377+Javi-kl@users.noreply.github.com> Date: Sun, 9 Nov 2025 06:50:27 +0100 Subject: [PATCH 1/4] #31 - python --- .../python/Javi-kl.py" | 270 ++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 "Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" diff --git "a/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" "b/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" new file mode 100644 index 0000000000..8a9ed8de0f --- /dev/null +++ "b/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" @@ -0,0 +1,270 @@ +from abc import ABC, abstractmethod +import random + +print("""¡Los JJOO de París 2024 han comenzado!""") + + +class IRegistro(ABC): + """Interfaz que define que hacer y NO como hacerlo + guardar y obtener datos en el registro""" + + @abstractmethod + def registrar(self, datos: str) -> bool: + pass + + @abstractmethod + def obtener_datos(self) -> list[str]: + pass + + +# Modulos bajo nivel, solo guardan datos +class DatosEventos(IRegistro): + def __init__(self): + self.datos_eventos = [] + + def registrar(self, dato: str) -> bool: + self.datos_eventos.append(dato) + return True + + def obtener_datos(self) -> list[str]: + return self.datos_eventos + + +class DatosUsuarios(IRegistro): + def __init__( + self, + ): + self.datos_usuarios = [] + + def registrar(self, dato: str) -> bool: + self.datos_usuarios.append(dato) + return True + + def obtener_datos(self) -> list[str]: + return self.datos_usuarios + + +class ResultadosEventos(IRegistro): # TODO + def __init__(self) -> None: + self.resultados_list = [] + + def registrar(self, dato: str) -> bool: + self.resultados_list.append(dato) + return True + + def obtener_datos(self) -> list[str]: + return self.resultados_list + + +class Evento: + def __init__(self, nombre) -> None: + self.nombre = nombre + + # cuando quiera imprimir este objeto deberá tener este metodo + def __str__( + self, + ) -> str: + return f"Evento: {self.nombre}" + + +class Participante: + def __init__(self, nombre, pais) -> None: + self.nombre = nombre + self.pais = pais + + # cuando quiera imprimir este objeto deberá tener este metodo + def __str__( + self, + ) -> str: + return f"Participante: {self.nombre}, Pais: {self.pais}" + + +class Resultado: + def __init__(self, dato) -> None: + + self.evento = dato["evento"] + self.oro = dato["medallas"][0] + self.plata = dato["medallas"][1] + self.bronce = dato["medallas"][2] + + # cuando quiera imprimir este objeto deberá tener este metodo + def __str__( + self, + ) -> str: + return f"{self.evento}\nOro: {self.oro}\nPlata: {self.plata}\nBronce: {self.bronce}" + + +class MedallaPais: # TODO logica + """Representa UNA medalla ganada por UN país""" + + def __init__(self, pais, medalla) -> None: # TODO + + self.pais = pais + self.medalla = medalla + + # cuando quiera imprimir este objeto deberá tener este metodo + def __str__( + self, + ) -> str: + return f"Pais: {self.pais}\nMedalla: {self.medalla}" + + +class SimuladorResultado: + @staticmethod + def simular(eventos, participantes): + datos_simulaciones = [] + for evento in eventos: + datos_evento = {} + top3 = sorted(participantes, key=lambda x: random.random()) + datos_evento["evento"] = evento + datos_evento["medallas"] = top3 + datos_simulaciones.append(datos_evento) + return datos_simulaciones + + +# Filtrar solo los ResultadoPaises +class CalculadorMedallas: + @staticmethod + def calcular_medallas(todos_los_datos): + # Filtrar solo los MedallaPais + solo_medallas = [ + dato for dato in todos_los_datos if isinstance(dato, MedallaPais) + ] + # Crear un diccionario para contar medallas por país + conteo_paises = {} + for medalla in solo_medallas: + pais = medalla.pais + tipo = medalla.medalla + if pais not in conteo_paises: + conteo_paises[pais] = {"oro": 0, "plata": 0, "bronce": 0, "total": 0} + conteo_paises[pais][tipo] += 1 # incrementa oro, plata o bronce + conteo_paises[pais]["total"] += 1 + + return sorted( + conteo_paises.items(), key=lambda item: item[1]["total"], reverse=True + ) + + +# Informador debe ser capaz de mostrar todo lo que Registrador puede registrar +class Informador: + """Modulo de alto nivel - muestra cualquier dato de los registros""" + + def __init__(self, registro: IRegistro): + self.registro = registro + + def mostrar_datos(self): + datos = self.registro.obtener_datos() + for dato in datos: + print(f"{dato}") + + +# Registrador +class Registrador: + """Modulo de alto nivel - registra cualquier cosa""" + + def __init__(self, registro: IRegistro): + self.registro = registro + + def registrar_datos(self, datos): + exito = self.registro.registrar(datos) + if exito: + print(f"Registrado con exito {datos}") + else: + print("Error al guardar") + + +# Eventos +datos_eventos = DatosEventos() # Primera instancia para acceder a los datos +# El registrador recibe la primera instancia creada no la clase +registrador_evento = Registrador(datos_eventos) + +# Participantes +datos_participantes = DatosUsuarios() +registrador_participante = Registrador(datos_participantes) + +# Simular resultados +simulador = SimuladorResultado() +calculador_medallas = CalculadorMedallas() +# Resultados +resultados = ResultadosEventos() +registrador_resultado = Registrador(resultados) + +# Informador +informador_resultados = Informador(resultados) + +"""informador_medallas = Informador(calculador_medallas_pais) +""" + + +# 6. Mostrar el ranking de países según el número de medallas. TODO +# permitir al usuario mediante gestor de opciones: +def menu_principal(): + while True: + print("Opciones:\n1. Registro de eventos.") + print("2. Registro de participantes.") + print("3. Simulación de eventos.") + print("4. Creación de informes.") + print("5. Salir del programa.") + opcion = input("-> ") + if opcion == "5": + break + + elif opcion == "4": + print(f"Informando de resultados") + informador_resultados.mostrar_datos() + """Ranking paises aqui""" # TODO + todos_los_datos = resultados.obtener_datos() + ranking = calculador_medallas.calcular_medallas(todos_los_datos) + for posicion, (pais, medallas) in enumerate(ranking, start=1): + print(f"{posicion}. {pais.upper()}") + print( + f" Oro: {medallas['oro']}, Plata: {medallas['plata']}, Bronce: {medallas['bronce']}" + ) + print(f" Total: {medallas['total']}\n") + + elif opcion == "3": + print("""\n¡Que comiencen los juegos!""") + datos_simulacion = simulador.simular( + datos_eventos.datos_eventos, datos_participantes.datos_usuarios + ) + for dato in datos_simulacion: + resultado = Resultado(dato) + print("""\n¡Registrando resultado de los eventos!""") + registrador_resultado.registrar_datos(resultado) + medalla_oro = MedallaPais(pais=dato["medallas"][0].pais, medalla="oro") + medalla_plata = MedallaPais( + pais=dato["medallas"][1].pais, medalla="plata" + ) + medalla_bronce = MedallaPais( + pais=dato["medallas"][2].pais, medalla="bronce" + ) + registrador_resultado.registrar_datos(medalla_oro) + registrador_resultado.registrar_datos(medalla_plata) + registrador_resultado.registrar_datos(medalla_bronce) + + elif opcion == "2": + print("""\n¡Creando participante!""") + # nombre = input("Nombre participante -> ") + # pais = input("Pais ->") + participante1 = Participante("javier", "spain") + participante2 = Participante("fran", "france") + participante3 = Participante("juan", "italy") + registrador_participante.registrar_datos(participante1) + registrador_participante.registrar_datos(participante2) + registrador_participante.registrar_datos(participante3) + + elif opcion == "1": + print("""\n¡Creando evento!""") + # nombre_evento = input("Nombre evento -> ") + evento1 = Evento("martillo") + evento2 = Evento("jabalina") + evento3 = Evento("peso") + registrador_evento.registrar_datos(evento1) + registrador_evento.registrar_datos(evento2) + registrador_evento.registrar_datos(evento3) + + else: + print("Elije una opción valida...") + + +menu_principal() From c10e2d9d41ad8d3fcd417f5b86eb20b7d5492ae1 Mon Sep 17 00:00:00 2001 From: javier <203809377+Javi-kl@users.noreply.github.com> Date: Sun, 9 Nov 2025 07:00:48 +0100 Subject: [PATCH 2/4] 31 - python --- .../python/Javi-kl.py" | 52 ++++++------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git "a/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" "b/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" index 8a9ed8de0f..f2084b5dec 100644 --- "a/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" +++ "b/Roadmap/31 - SIMULADOR JUEGOS OL\303\215MPICOS/python/Javi-kl.py" @@ -31,9 +31,7 @@ def obtener_datos(self) -> list[str]: class DatosUsuarios(IRegistro): - def __init__( - self, - ): + def __init__(self): self.datos_usuarios = [] def registrar(self, dato: str) -> bool: @@ -44,7 +42,7 @@ def obtener_datos(self) -> list[str]: return self.datos_usuarios -class ResultadosEventos(IRegistro): # TODO +class ResultadosEventos(IRegistro): def __init__(self) -> None: self.resultados_list = [] @@ -60,7 +58,6 @@ class Evento: def __init__(self, nombre) -> None: self.nombre = nombre - # cuando quiera imprimir este objeto deberá tener este metodo def __str__( self, ) -> str: @@ -72,7 +69,6 @@ def __init__(self, nombre, pais) -> None: self.nombre = nombre self.pais = pais - # cuando quiera imprimir este objeto deberá tener este metodo def __str__( self, ) -> str: @@ -87,22 +83,20 @@ def __init__(self, dato) -> None: self.plata = dato["medallas"][1] self.bronce = dato["medallas"][2] - # cuando quiera imprimir este objeto deberá tener este metodo def __str__( self, ) -> str: return f"{self.evento}\nOro: {self.oro}\nPlata: {self.plata}\nBronce: {self.bronce}" -class MedallaPais: # TODO logica +class MedallaPais: """Representa UNA medalla ganada por UN país""" - def __init__(self, pais, medalla) -> None: # TODO + def __init__(self, pais, medalla) -> None: self.pais = pais self.medalla = medalla - # cuando quiera imprimir este objeto deberá tener este metodo def __str__( self, ) -> str: @@ -122,15 +116,12 @@ def simular(eventos, participantes): return datos_simulaciones -# Filtrar solo los ResultadoPaises class CalculadorMedallas: @staticmethod def calcular_medallas(todos_los_datos): - # Filtrar solo los MedallaPais solo_medallas = [ dato for dato in todos_los_datos if isinstance(dato, MedallaPais) ] - # Crear un diccionario para contar medallas por país conteo_paises = {} for medalla in solo_medallas: pais = medalla.pais @@ -145,7 +136,7 @@ def calcular_medallas(todos_los_datos): ) -# Informador debe ser capaz de mostrar todo lo que Registrador puede registrar +# Informador class Informador: """Modulo de alto nivel - muestra cualquier dato de los registros""" @@ -174,8 +165,7 @@ def registrar_datos(self, datos): # Eventos -datos_eventos = DatosEventos() # Primera instancia para acceder a los datos -# El registrador recibe la primera instancia creada no la clase +datos_eventos = DatosEventos() registrador_evento = Registrador(datos_eventos) # Participantes @@ -192,12 +182,8 @@ def registrar_datos(self, datos): # Informador informador_resultados = Informador(resultados) -"""informador_medallas = Informador(calculador_medallas_pais) -""" - -# 6. Mostrar el ranking de países según el número de medallas. TODO -# permitir al usuario mediante gestor de opciones: +# 6. Mostrar el ranking de países según el número de medallas. def menu_principal(): while True: print("Opciones:\n1. Registro de eventos.") @@ -212,7 +198,7 @@ def menu_principal(): elif opcion == "4": print(f"Informando de resultados") informador_resultados.mostrar_datos() - """Ranking paises aqui""" # TODO + """Ranking paises aqui""" todos_los_datos = resultados.obtener_datos() ranking = calculador_medallas.calcular_medallas(todos_los_datos) for posicion, (pais, medallas) in enumerate(ranking, start=1): @@ -244,24 +230,16 @@ def menu_principal(): elif opcion == "2": print("""\n¡Creando participante!""") - # nombre = input("Nombre participante -> ") - # pais = input("Pais ->") - participante1 = Participante("javier", "spain") - participante2 = Participante("fran", "france") - participante3 = Participante("juan", "italy") - registrador_participante.registrar_datos(participante1) - registrador_participante.registrar_datos(participante2) - registrador_participante.registrar_datos(participante3) + nombre = input("Nombre participante -> ") + pais = input("Pais ->") + participante = Participante(nombre, pais) + registrador_participante.registrar_datos(participante) elif opcion == "1": print("""\n¡Creando evento!""") - # nombre_evento = input("Nombre evento -> ") - evento1 = Evento("martillo") - evento2 = Evento("jabalina") - evento3 = Evento("peso") - registrador_evento.registrar_datos(evento1) - registrador_evento.registrar_datos(evento2) - registrador_evento.registrar_datos(evento3) + nombre_evento = input("Nombre evento -> ") + evento = Evento(nombre_evento) + registrador_evento.registrar_datos(evento) else: print("Elije una opción valida...") From 57ad82b89b6f2c90177f6d9a1bc63e74cb4fb1a1 Mon Sep 17 00:00:00 2001 From: javier <203809377+Javi-kl@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:25:49 +0100 Subject: [PATCH 3/4] reto-32-python in progress --- .../python/javi-kl.py | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py diff --git a/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py b/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py new file mode 100644 index 0000000000..5683b6c33f --- /dev/null +++ b/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py @@ -0,0 +1,98 @@ +from abc import ABC, abstractmethod # para clases abstractas y metodos +import random # Para crear números random +import time # para crear lapso de tiempo 1 seg + + +class Interfaz(ABC): # interfaz que seguiran mis superheroes + @abstractmethod + def __init__(self) -> None: # atributos + self.vida = None + + @abstractmethod + def atacar(self) -> int: # metodo para atacar que devuelve valor + pass + + @abstractmethod + def evadir(self) -> bool: # metodo para evadir que devuelve true o false + pass + + @abstractmethod + def mostrar_vida(self) -> int: # metodo para mostrar la vida + pass + + +class Wolverine(Interfaz): + def __init__(self) -> None: + self.vida = 300 + + def atacar(self) -> int: + daño_aleatorio = random.randint(10, 120) # genera un rango aleatorio + return daño_aleatorio + + def evadir(self) -> bool: + num_evasion = random.randint( + 0, 100 + ) # si sale menor que la probabilidad de evadir, True + return num_evasion < 20 + + def mostrar_vida(self) -> int: # devuelve la vida actual + return self.vida + + +class Deadpool(Interfaz): + def __init__(self) -> None: + self.vida = 300 + + def atacar(self) -> int: + daño_aleatorio = random.randint(10, 100) + return daño_aleatorio + + def evadir(self) -> bool: + num_evasion = random.randint(0, 100) + return num_evasion < 25 + + def mostrar_vida(self) -> int: + return self.vida + + +wolverine = Wolverine() +deadpool = Deadpool() + + +# Faltaría hacer que simule hasta que uno gane, con un bucle +class Simulador: + def __init__(self) -> None: + self.turno = 0 + + def siguiente_turno(self): + self.turno += 1 + # agregar la espera de 1 seg + + def omitir_turno(self): + self.turno += 2 + # agregar la espera de 1 seg + + def simular(self): + + if self.turno % 2 == 0: + daño = wolverine.atacar() + exito_evadir = deadpool.evadir() + if exito_evadir: + print("Deadpool ha evadido con exito") + Simulador.siguiente_turno(self) + + else: + if daño == 120: + print("Wolverine ha inflingido golpe critico") + print("Volverá a atacar en el siguiente turno") + Simulador.omitir_turno(self) + + print(f"Wolverine ha inflingido {daño} puntos de daño.") + Simulador.siguiente_turno(self) + else: + daño = deadpool.atacar() + exito_evadir = wolverine.evadir() + + +simulador = Simulador() +simulador.simular() From 2509893b9cfecd04cc1eac07b4417f7389532384 Mon Sep 17 00:00:00 2001 From: javier <203809377+Javi-kl@users.noreply.github.com> Date: Tue, 11 Nov 2025 09:59:51 +0100 Subject: [PATCH 4/4] #32 - python --- .../python/javi-kl.py | 126 ++++++++++++------ 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py b/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py index 5683b6c33f..badd235700 100644 --- a/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py +++ b/Roadmap/32 - BATALLA DEADPOOL Y WOLVERINE/python/javi-kl.py @@ -1,47 +1,52 @@ -from abc import ABC, abstractmethod # para clases abstractas y metodos -import random # Para crear números random -import time # para crear lapso de tiempo 1 seg +from abc import ABC, abstractmethod +import random +import time -class Interfaz(ABC): # interfaz que seguiran mis superheroes +class Interfaz(ABC): @abstractmethod - def __init__(self) -> None: # atributos - self.vida = None + def __init__(self, vida) -> None: + self.vida = vida @abstractmethod - def atacar(self) -> int: # metodo para atacar que devuelve valor + def atacar(self) -> int: + pass + + @abstractmethod + def evadir(self) -> bool: pass @abstractmethod - def evadir(self) -> bool: # metodo para evadir que devuelve true o false + def devolver_vida(self) -> int: pass @abstractmethod - def mostrar_vida(self) -> int: # metodo para mostrar la vida + def recibir_daño(self, daño) -> None: pass class Wolverine(Interfaz): - def __init__(self) -> None: - self.vida = 300 + def __init__(self, vida) -> None: + self.vida = vida def atacar(self) -> int: - daño_aleatorio = random.randint(10, 120) # genera un rango aleatorio + daño_aleatorio = random.randint(10, 120) return daño_aleatorio def evadir(self) -> bool: - num_evasion = random.randint( - 0, 100 - ) # si sale menor que la probabilidad de evadir, True + num_evasion = random.randint(0, 100) return num_evasion < 20 - def mostrar_vida(self) -> int: # devuelve la vida actual + def devolver_vida(self) -> int: return self.vida + def recibir_daño(self, daño) -> None: + self.vida -= daño + class Deadpool(Interfaz): - def __init__(self) -> None: - self.vida = 300 + def __init__(self, vida) -> None: + self.vida = vida def atacar(self) -> int: daño_aleatorio = random.randint(10, 100) @@ -51,47 +56,84 @@ def evadir(self) -> bool: num_evasion = random.randint(0, 100) return num_evasion < 25 - def mostrar_vida(self) -> int: + def devolver_vida(self) -> int: return self.vida + def recibir_daño(self, daño) -> None: + self.vida -= daño -wolverine = Wolverine() -deadpool = Deadpool() + +wolverine = Wolverine(500) +deadpool = Deadpool(500) -# Faltaría hacer que simule hasta que uno gane, con un bucle class Simulador: def __init__(self) -> None: self.turno = 0 def siguiente_turno(self): + print("Cambio de turno") + time.sleep(1) self.turno += 1 - # agregar la espera de 1 seg def omitir_turno(self): + print("Turno omitido por golpe critico") + time.sleep(1) self.turno += 2 - # agregar la espera de 1 seg def simular(self): - - if self.turno % 2 == 0: - daño = wolverine.atacar() - exito_evadir = deadpool.evadir() - if exito_evadir: - print("Deadpool ha evadido con exito") - Simulador.siguiente_turno(self) - + """Si la vida de uno es menor a 0 finaliza el combate, + si el turno es par ataca Wolverino, si no Deadpool""" + + while True: + vida_wolverine = wolverine.devolver_vida() + vida_deadpool = deadpool.devolver_vida() + if vida_deadpool <= 0: + print("Wolverine derroto a su oponente") + break + elif vida_wolverine <= 0: + print("Deadpool derroto a su oponente") + break else: - if daño == 120: - print("Wolverine ha inflingido golpe critico") - print("Volverá a atacar en el siguiente turno") - Simulador.omitir_turno(self) - - print(f"Wolverine ha inflingido {daño} puntos de daño.") - Simulador.siguiente_turno(self) - else: - daño = deadpool.atacar() - exito_evadir = wolverine.evadir() + print( + f"Puntos de vida\nWolverine: {vida_wolverine}\nDeadpool: {vida_deadpool}" + ) + print(f"\nTurno {self.turno}") + + if self.turno % 2 == 0: + daño = wolverine.atacar() + exito_evadir = deadpool.evadir() + if exito_evadir: + print("Deadpool ha evadido con exito") + Simulador.siguiente_turno(self) + + else: + deadpool.recibir_daño(daño) + + if daño == 120: + print("Wolverine inflinge golpe critico") + print("Volverá a atacar en el siguiente turno") + Simulador.omitir_turno(self) + + print(f"Wolverine inflinge {daño} puntos de daño.") + Simulador.siguiente_turno(self) + + else: + daño = deadpool.atacar() + exito_evadir = wolverine.evadir() + if exito_evadir: + print("Wolverine ha evadido con exito") + Simulador.siguiente_turno(self) + + else: + wolverine.recibir_daño(daño) + if daño == 100: + print("Deadpool inflinge golpe critico") + print("Volverá a atacar en el siguiente turno") + Simulador.omitir_turno(self) + + print(f"Deadpool inflinge {daño} puntos de daño.") + Simulador.siguiente_turno(self) simulador = Simulador()