-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corrección Roadmap 41 + Nuevo ejercicio 42
- Loading branch information
Showing
3 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import zipfile | ||
import os | ||
|
||
|
||
def zip_file(path: str, file: str) -> str: | ||
|
||
file_path = os.path.join(path, file) | ||
|
||
if os.path.exists(file_path): | ||
|
||
zip_file = f"{file}.zip" | ||
zip_path = os.path.join(path, zip_file) | ||
|
||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf: | ||
zipf.write(file_path, file) | ||
print(f"Archivo {file} comprimido como {zip_file}.") | ||
return zip_file | ||
|
||
else: | ||
print(f"El archivo {file} no existe el directorio {path}.") | ||
|
||
return None | ||
|
||
|
||
def unzip_file(path: str, file: str): | ||
|
||
file_path = os.path.join(path, file) | ||
|
||
if os.path.exists(file_path): | ||
|
||
zip_path = os.path.join(path, file) | ||
|
||
with zipfile.ZipFile(zip_path) as zipf: | ||
zipf.extractall(path) | ||
print(f"Archivo {file} descomprimido en {path}.") | ||
|
||
else: | ||
print(f"El archivo {file} no existe el directorio {path}.") | ||
|
||
|
||
path = os.path.dirname(os.path.abspath(__file__)) # Directorio actual | ||
file = "nombre_de_mi_archivo" | ||
|
||
zip = zip_file(path, file) | ||
|
||
if zip != None: | ||
|
||
# Borro el fichero original antes de descomprimir el zip | ||
os.remove(os.path.join(path, file)) | ||
|
||
unzip_file(path, zip) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# #42 TORNEO DRAGON BALL | ||
> #### Dificultad: Difícil | Publicación: 14/10/24 | Corrección: 21/10/24 | ||
## Ejercicio | ||
|
||
``` | ||
/* | ||
* EJERCICIO: | ||
* ¡El último videojuego de Dragon Ball ya está aquí! | ||
* Se llama Dragon Ball: Sparking! ZERO. | ||
* | ||
* Simula un Torneo de Artes Marciales, al más puro estilo | ||
* de la saga, donde participarán diferentes luchadores, y el | ||
* sistema decidirá quién es el ganador. | ||
* | ||
* Luchadores: | ||
* - Nombre. | ||
* - Tres atributos: velocidad, ataque y defensa | ||
* (con valores entre 0 a 100 que tú decidirás). | ||
* - Comienza cada batalla con 100 de salud. | ||
* Batalla: | ||
* - En cada batalla se enfrentan 2 luchadores. | ||
* - El luchador con más velocidad comienza atacando. | ||
* - El daño se calcula restando el daño de ataque del | ||
* atacante menos la defensa del oponente. | ||
* - El oponente siempre tiene un 20% de posibilidad de | ||
* esquivar el ataque. | ||
* - Si la defensa es mayor que el ataque, recibe un 10% | ||
* del daño de ataque. | ||
* - Después de cada turno y ataque, el oponente pierde salud. | ||
* - La batalla finaliza cuando un luchador pierde toda su salud. | ||
* Torneo: | ||
* - Un torneo sólo es válido con un número de luchadores | ||
* potencia de 2. | ||
* - El torneo debe crear parejas al azar en cada ronda. | ||
* - Los luchadores se enfrentan en rondas eliminatorias. | ||
* - El ganador avanza a la siguiente ronda hasta que sólo | ||
* quede uno. | ||
* - Debes mostrar por consola todo lo que sucede en el torneo, | ||
* así como el ganador. | ||
*/ | ||
``` | ||
#### Tienes toda la información extendida sobre el roadmap de retos de programación en **[retosdeprogramacion.com/roadmap](https://retosdeprogramacion.com/roadmap)**. | ||
|
||
Sigue las **[instrucciones](../../README.md)**, consulta las correcciones y aporta la tuya propia utilizando el lenguaje de programación que quieras. | ||
|
||
> Recuerda que cada semana se publica un nuevo ejercicio y se corrige el de la semana anterior en directo desde **[Twitch](https://twitch.tv/mouredev)**. Tienes el horario en la sección "eventos" del servidor de **[Discord](https://discord.gg/mouredev)**. |