Created
September 24, 2017 08:01
-
-
Save KeronCyst/caf973251ba496e95b5b47b347b7e778 to your computer and use it in GitHub Desktop.
Number Guesser
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
minimum, maximum, guess_count = 0, 100, 0 | |
print("Please think of a number between 0 and 100!") | |
while True: | |
number = int((minimum + maximum) / 2) | |
user_input = input("Is your secret number " + str(number) + "?\nEnter 'h' to indicate the guess is too high.\n\ | |
Enter 'l' to indicate the guess is too low.\nEnter 'c' to indicate I guessed correctly.\nEnter 'm' if you made a mistake.") | |
guess_count += 1 | |
if user_input == "c": | |
break | |
elif user_input == "h": | |
maximum = number | |
elif user_input == "l": | |
minimum = number | |
elif user_input == "m": | |
print("Alrighty then, let's start over.") | |
minimum, maximum, guess_count = 0, 100, 0 | |
else: | |
print("Sorry, I did not understand your input.") | |
guess_count -= 1 | |
correct_guess = "Gotcha! I guessed your secret number " + str(number) + " in " + str(guess_count) | |
if guess_count == 1: | |
print(correct_guess + " try. Oh, come on!") | |
else: | |
print(correct_guess + " tries.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment