Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. print ("Please think of a number between 0 and 100! ")
  2.  
  3. high = 100
  4. low = 0
  5. ans = int((high + low)/2)
  6.  
  7. print ("Is your secret number "+ str(ans) + "?")
  8.  
  9.  
  10. var = 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.")
  11.  
  12. def get_input():
  13. return 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: ")
  14. while var != 'c':
  15.  
  16. if var == 'h':
  17. high = ans
  18. ans = int((high + low)/2)
  19. print ("Is your secret number "+ str(ans) + "?")
  20. var = get_input ()
  21.  
  22.  
  23.  
  24. elif var == 'l':
  25. low = ans
  26. ans = int((high + low)/2)
  27. print ("Is your secret number "+ str(ans) + "?")
  28. var = get_input ()
  29.  
  30.  
  31.  
  32. elif var == 'c':
  33. print ("Game over. Your secret number was: " + str(ans))
  34. break
  35. else:
  36. print('Sorry, I did not understand your input.')
  37. print ("Is your secret number "+ str(ans) + "?")
  38. var = get_input ()
  39.  
  40. print ("Game over. Your secret number was: " + str(ans))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement