forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 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
82 changes: 82 additions & 0 deletions
82
Retos/Reto #46 - LA CARRERA DE COCHES [Media]/python/mouredev.py
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,82 @@ | ||
import random | ||
import time | ||
import os | ||
|
||
|
||
def race(track_length: int): | ||
|
||
track1, track2 = create_tracks(track_length) | ||
|
||
print_race(track1, track2) | ||
|
||
position1, position2 = len(track1) - 1, len(track2) - 1 | ||
crash1, crash2 = False, False | ||
|
||
while position1 > 0 and position2 > 0: | ||
|
||
time.sleep(0.5) | ||
|
||
track1[position1] = "_" | ||
track2[position2] = "_" | ||
|
||
position1 -= 0 if crash1 else random.randint(1, 3) | ||
position2 -= 0 if crash2 else random.randint(1, 3) | ||
|
||
crash1, crash2 = False, False | ||
|
||
position1 = 0 if position1 < 0 else position1 | ||
position2 = 0 if position2 < 0 else position2 | ||
|
||
if track1[position1] == "🌲": | ||
crash1 = True | ||
if track2[position2] == "🌲": | ||
crash2 = True | ||
|
||
track1[position1] = "💥" if crash1 else "🚙" | ||
track2[position2] = "💥" if crash2 else "🚗" | ||
|
||
print_race(track1, track2) | ||
|
||
check_race(position1, position2) | ||
|
||
|
||
def create_tracks(track_length: int) -> (list, list): | ||
|
||
track = ["_"] * track_length | ||
|
||
def add_trees(track: list) -> list: | ||
trees = random.randint(1, 3) | ||
for _ in range(trees): | ||
position = random.randint(0, len(track) - 1) | ||
track[position] = "🌲" | ||
|
||
return track | ||
|
||
track1, track2 = add_trees(track.copy()), add_trees(track.copy()) | ||
|
||
track1.insert(0, "🏁") | ||
track1.append("🚙") | ||
track2.insert(0, "🏁") | ||
track2.append("🚗") | ||
|
||
return (track1, track2) | ||
|
||
|
||
def print_race(track1: list, track2: list): | ||
os.system("clear") | ||
# os.system("cls") Windows | ||
print("".join(track1)) | ||
print("".join(track2)) | ||
print("") | ||
|
||
|
||
def check_race(position1: int, position2: int): | ||
if position1 == 0 and position2 == 0: | ||
print("Empate") | ||
elif position1 == 0: | ||
print("Ha ganado el coche 🚙") | ||
elif position2 == 0: | ||
print("Ha ganado el coche 🚗") | ||
|
||
|
||
race(20) |
25 changes: 25 additions & 0 deletions
25
Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [Fácil]/ejercicio.md
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,25 @@ | ||
# Reto #47: La palabra de 100 puntos | ||
#### Dificultad: Fácil | Publicación: 04/12/23 | Corrección: 11/12/23 | ||
|
||
## Enunciado | ||
|
||
``` | ||
/* | ||
* La última semana de 2021 comenzamos la actividad de retos de programación, | ||
* con la intención de resolver un ejercicio cada semana para mejorar | ||
* nuestra lógica... ¡Hemos llegado al EJERCICIO 100! Gracias 🙌 | ||
* | ||
* Crea un programa que calcule los puntos de una palabra. | ||
* - Cada letra tiene un valor asignado. Por ejemplo, en el abecedario | ||
* español de 27 letras, la A vale 1 y la Z 27. | ||
* - El programa muestra el valor de los puntos de cada palabra introducida. | ||
* - El programa finaliza si logras introducir una palabra de 100 puntos. | ||
* - Puedes usar la terminal para interactuar con el usuario y solicitarle | ||
* cada palabra. | ||
*/ | ||
``` | ||
#### Tienes toda la información extendida sobre los retos de programación semanales en **[retosdeprogramacion.com/semanales2023](https://retosdeprogramacion.com/semanales2023)**. | ||
|
||
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)**. |