import random
import sys

SECRET_LEN = 4           # Cambia a 3–6 si quieres otra dificultad
DIGITS = "0123456789"    # Se permiten ceros a la izquierda
ALLOW_REPEATS = False    # Si lo pones True, deja dígitos repetidos

def generar_secreto(n=SECRET_LEN, allow_repeats=ALLOW_REPEATS):
    if allow_repeats:
        return "".join(random.choice(DIGITS) for _ in range(n))
    else:
        return "".join(random.sample(DIGITS, n))

def evaluar(guess: str, secret: str):
    fijas = sum(g == s for g, s in zip(guess, secret))
    picas = sum(min(guess.count(d), secret.count(d)) for d in set(DIGITS)) - fijas
    return picas, fijas

def valida(guess: str, n: int, allow_repeats: bool):
    if len(guess) != n or not guess.isdigit():
        return f"Ingresa exactamente {n} dígitos."
    if not allow_repeats and len(set(guess)) != n:
        return "No se permiten dígitos repetidos."
    return None

def main():
    print("🎮 Picas y Fijas")
    print(f"- Adivina un número secreto de {SECRET_LEN} dígitos "
          f"{'con' if ALLOW_REPEATS else 'sin'} repetidos.")
    print("Comandos: 'salir' para terminar, 'rendirse' para revelar el número.\n")

    secret = generar_secreto()
    intentos = 0

    while True:
        guess = input("Tu intento: ").strip()
        if guess.lower() == "salir":
            print("¡Hasta luego!")
            sys.exit(0)
        if guess.lower() == "rendirse":
            print(f"El número secreto era: {secret}")
            sys.exit(0)

        error = valida(guess, SECRET_LEN, ALLOW_REPEATS)
        if error:
            print("⚠️", error)
            continue

        intentos += 1
        picas, fijas = evaluar(guess, secret)
        if fijas == SECRET_LEN:
            print(f"✅ ¡Acertaste en {intentos} intento(s)! El número era {secret}.")
            break
        else:
            print(f"Resultado → Picas: {picas} | Fijas: {fijas}")

if __name__ == "__main__":
    main()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: