Created
June 14, 2017 09:17
-
-
Save akshayxarora/6345a2c034ab316e01a83798dfc26458 to your computer and use it in GitHub Desktop.
guess the number
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
print("Please think of a number between 0 and 100!") | |
low = 0 | |
high = 100 | |
ans = int((low + high) / 2) | |
while True: | |
print("Is your secret number %d " %ans) | |
userguess = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ") | |
if userguess == 'h': | |
high = ans | |
elif userguess == 'l': | |
low = ans | |
elif userguess == 'c': | |
break | |
else : | |
print("Sorry, I did not understand your input.") | |
continue | |
ans = int((low + high) / 2) | |
print("Game over. Your secret number was: %d" %ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment