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.
Merge pull request mouredev#5765 from MarcosDigu/main
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
Retos/Reto #2 - EL PARTIDO DE TENIS [Media]/python/MarcosDigu.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,41 @@ | ||
import os | ||
|
||
os.system('cls') | ||
|
||
puntaje = ["0", "15", "30", "40", "Ad"] | ||
|
||
P1 = puntaje[0] | ||
P2 = puntaje[0] | ||
|
||
game_finished = False | ||
|
||
while not game_finished: | ||
print(f"Score P1: {P1}") | ||
print(f"Score P2: {P2}") | ||
print(" ") | ||
|
||
winner = input("Type P1 or P2: ") | ||
|
||
if P1 == "Ad" and P2 == "40" and winner == "P1": | ||
game_finished = True | ||
elif P2 == "Ad" and P1 == "40" and winner == "P2": | ||
game_finished = True | ||
else: | ||
index_P1 = puntaje.index(P1) | ||
index_P2 = puntaje.index(P2) | ||
|
||
if winner == "P1": | ||
P1 = puntaje[index_P1 + 1] | ||
if P1 == "Ad" and P2 in ["0", "15", "30"]: | ||
game_finished = True | ||
else: | ||
P2 = puntaje[index_P2 + 1] | ||
if P2 == "Ad" and P1 in ["0", "15", "30"]: | ||
game_finished = True | ||
|
||
os.system('cls') | ||
|
||
if P1 == "Ad": | ||
print("Player 1 won") | ||
else: | ||
print("Player 2 won") |
43 changes: 43 additions & 0 deletions
43
Retos/Reto #3 - EL GENERADOR DE CONTRASEÑAS [Media]/python/MarcosDigu.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,43 @@ | ||
""" | ||
* Escribe un programa que sea capaz de generar contraseñas de forma aleatoria. | ||
* Podrás configurar generar contraseñas con los siguientes parámetros: | ||
* - Longitud: Entre 8 y 16. | ||
* - Con o sin letras mayúsculas. | ||
* - Con o sin números. | ||
* - Con o sin símbolos. | ||
* (Pudiendo combinar todos estos parámetros entre ellos) | ||
""" | ||
import string | ||
import random | ||
import os | ||
|
||
os.system('cls') | ||
|
||
def generate_password(length, use_uppercase, use_numbers, use_symbols): | ||
characters = "" | ||
|
||
if use_uppercase: | ||
characters += string.ascii_uppercase | ||
if use_numbers: | ||
characters += string.digits | ||
if use_symbols: | ||
characters += "!@#$%^&*()_-+=<>?/[]{}|" | ||
|
||
if not any([use_uppercase, use_numbers, use_symbols]): | ||
# If no character type is selected, default to lowercase letters | ||
characters = string.ascii_lowercase | ||
|
||
password = ''.join(random.choice(characters) for _ in range(length)) | ||
return password | ||
|
||
char = int(input("Number of characters (8-16): ")) | ||
uplo = input("U: Include uppercase - L: Lowercase only: ") | ||
num = input("Include numbers (y/n): ") | ||
sym = input("Include symbols (y/n): ") | ||
|
||
# Validate input for the number of characters | ||
char = max(8, min(char, 16)) | ||
|
||
password = generate_password(char, uplo == "U", num == "y", sym == "y") | ||
|
||
print(f"Your password is: {password}") |
31 changes: 31 additions & 0 deletions
31
Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/python/MarcosDigu.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,31 @@ | ||
def es_primo(num): | ||
"""Verifica si un número es primo.""" | ||
if num < 2: | ||
return False | ||
for i in range(2, int(num**0.5) + 1): | ||
if num % i == 0: | ||
return False | ||
return True | ||
|
||
def es_numero_fibonacci(num): | ||
"""Verifica si un número es un número de Fibonacci.""" | ||
def es_cuadrado_perfecto(n): | ||
"""Verifica si un número es un cuadrado perfecto.""" | ||
raiz = int(n**0.5) | ||
return n == raiz**2 | ||
|
||
return es_cuadrado_perfecto(5 * num**2 + 4) or es_cuadrado_perfecto(5 * num**2 - 4) | ||
|
||
def es_par(num): | ||
"""Verifica si un número es par.""" | ||
return num % 2 == 0 | ||
|
||
def checker(num): | ||
"""Imprime información sobre si un número es primo, de Fibonacci y par.""" | ||
primo = "primo" if es_primo(num) else "compuesto" | ||
fibo = "fibonacci" if es_numero_fibonacci(num) else "no fibonacci" | ||
par = "par" if es_par(num) else "impar" | ||
|
||
print(f"El número {num} es {primo}, {fibo} y {par}.") | ||
|
||
checker(10) |