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#5795 from danielzx9/main
Reto #3 - Python
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Retos/Reto #3 - EL GENERADOR DE CONTRASEÑAS [Media]/python/danielzx9.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,44 @@ | ||
|
||
'''``` | ||
/* | ||
* 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 | ||
|
||
def contra(longitudContra, mayus, numeros, simbol): | ||
caracteres = string.ascii_lowercase | ||
if mayus: | ||
caracteres += string.ascii_uppercase | ||
if numeros: | ||
caracteres += string.digits | ||
if simbol: | ||
caracteres += string.punctuation | ||
|
||
contrasena = ''.join(random.choice(caracteres) for _ in range(longitudContra)) | ||
return contrasena | ||
|
||
def main(): | ||
longitudContra = int(input("Ingrese la longitud que desea para la contraseña (entre 8 y 16): ")) | ||
if not (8 <= longitudContra <= 16): | ||
print("Longitud no válida. Debe estar entre 8 y 16 caracteres.") | ||
return | ||
|
||
mayus = input("Incluir letras mayúsculas (si/no): ").lower() == 'si' | ||
numeros = input("Incluir números (si/no): ").lower() == 'si' | ||
simbol = input("Incluir símbolos (si/no): ").lower() == 'si' | ||
|
||
contrasena = contra(longitudContra, mayus, numeros, simbol) | ||
print(f"\nContraseña generada: {contrasena}") | ||
|
||
if __name__ == "__main__": | ||
main() |
46 changes: 46 additions & 0 deletions
46
Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/python/danielzx9.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,46 @@ | ||
''' * Escribe un programa que, dado un número, compruebe y muestre si es primo, fibonacci y par. | ||
* Ejemplos: | ||
* - Con el número 2, nos dirá: "2 es primo, fibonacci y es par" | ||
* - Con el número 7, nos dirá: "7 es primo, no es fibonacci y es impar"''' | ||
|
||
def par(num): | ||
return num % 2 == 0 | ||
|
||
def primo(num): | ||
if num < 2: | ||
return False | ||
for i in range(2, int(num**0.5) + 1): | ||
if num % i == 0: | ||
return False | ||
return True | ||
|
||
def fibo(num): | ||
a, b = 0, 1 | ||
while a < num: | ||
a, b = b, a + b | ||
return a == num | ||
|
||
def veri(): | ||
try: | ||
num = int(input("Ingrese un número: ")) | ||
if primo(num) and fibo(num) and par(num): | ||
print(f"{num} es primo, fibonacci y es par") | ||
elif primo(num) and fibo(num) and not par(num): | ||
print(f"{num} es primo, fibonacci y es impar") | ||
elif primo(num) and not fibo(num) and par(num): | ||
print(f"{num} es primo, no es fibonacci y es par") | ||
elif primo(num) and not fibo(num) and not par(num): | ||
print(f"{num} es primo, no es fibonacci y es impar") | ||
elif not primo(num) and fibo(num) and par(num): | ||
print(f"{num} no es primo, es fibonacci y es par") | ||
elif not primo(num) and fibo(num) and not par(num): | ||
print(f"{num} no es primo, es fibonacci y es impar") | ||
elif not primo(num) and not fibo(num) and par(num): | ||
print(f"{num} no es primo, no es fibonacci y es par") | ||
elif not primo(num) and not fibo(num) and not par(num): | ||
print(f"{num} no es primo, no es fibonacci y es impar") | ||
except ValueError: | ||
print("Por favor, ingrese un número válido.") | ||
|
||
|
||
veri() |