Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juego #271

Open
STEPHKINGS opened this issue Sep 16, 2024 · 0 comments
Open

Juego #271

STEPHKINGS opened this issue Sep 16, 2024 · 0 comments

Comments

@STEPHKINGS
Copy link

import random

def adivina_el_numero():
print("¡Bienvenido al juego de Adivina el Número!")
numero_secreto = random.randint(1, 100) # Número aleatorio entre 1 y 100
intentos = 0

while True:
    intento = input("Adivina un número entre 1 y 100: ")
    
    try:
        intento = int(intento)
    except ValueError:
        print("Por favor, ingresa un número válido.")
        continue
    
    intentos += 1

    if intento < numero_secreto:
        print("El número es mayor.")
    elif intento > numero_secreto:
        print("El número es menor.")
    else:
        print(f"¡Felicidades! Adivinaste el número en {intentos} intentos.")
        break

Ejecutar el juego

adivina_el_numero()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant