Last active
May 13, 2022 15:17
-
-
Save RodolfoFerro/c8f276e16414169b3ec76a5ebf4126be to your computer and use it in GitHub Desktop.
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
intentos = 0 | |
lim_inf, lim_sup = 0, 10 | |
numero = int(input("Ingrese un dígito: ")) | |
busqueda = 5 | |
while True: | |
intentos += 1 | |
if numero == busqueda: | |
break | |
elif numero > busqueda: | |
lim_inf, busqueda = busqueda, (busqueda + lim_sup) // 2 | |
else: | |
lim_sup, busqueda = busqueda, (busqueda + lim_inf) // 2 | |
print(f"En {intentos} intentos, el número es: {busqueda}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment