Skip to content

Instantly share code, notes, and snippets.

@RodolfoFerro
Last active May 13, 2022 15:17
Show Gist options
  • Save RodolfoFerro/c8f276e16414169b3ec76a5ebf4126be to your computer and use it in GitHub Desktop.
Save RodolfoFerro/c8f276e16414169b3ec76a5ebf4126be to your computer and use it in GitHub Desktop.
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