Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akshayxarora/6345a2c034ab316e01a83798dfc26458 to your computer and use it in GitHub Desktop.
Save akshayxarora/6345a2c034ab316e01a83798dfc26458 to your computer and use it in GitHub Desktop.
guess the number
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