Skip to content

Commit

Permalink
Merge pull request mouredev#5765 from MarcosDigu/main
Browse files Browse the repository at this point in the history
Reto #2, #3, #4 - Python
  • Loading branch information
Roswell468 authored Nov 18, 2023
2 parents 4803a0b + 4738a5f commit 39b01a3
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Retos/Reto #2 - EL PARTIDO DE TENIS [Media]/python/MarcosDigu.py
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")
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}")
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)

0 comments on commit 39b01a3

Please sign in to comment.