Last active
April 7, 2021 10:48
-
-
Save hamzahamidi/5395344e093f31404b0ddbc7a9b01d76 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
def validate(num, name): | |
if not num.isnumeric(): | |
raise ValueError(f'Le format de {name} n\'est pas valide') | |
output = int(num) | |
if output < 0 or 100 < output: | |
raise ValueError( | |
f'La veleur de {name} doit être comprise entre 0 et 100') | |
return output | |
a = input('Entrez la valeur de A: ') | |
a = validate(a, 'A') | |
def bs(left=0, right=100): | |
m = left + (right - left) // 2 | |
if right < left: | |
raise ValueError(f'Le nombre {a} n\'existe pas entre 0 entre 100.') | |
reponse = input(f'Est ce le nombre {m} ? ') | |
if reponse == 'oui': | |
return f'Trouvé! le nombre est {m}' | |
elif reponse == 'plus grand' or reponse == 'g': | |
return bs( m +1, right) | |
elif reponse == 'plus petit' or reponse == 'p': | |
return bs(left, m - 1) | |
else: | |
print('Réponse invalide. Veuillez répéter svp!') | |
return bs(left, right) | |
print(bs()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment