Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 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.  
  13. while var != 'c':
  14.  
  15. if var == 'h':
  16. high = ans
  17. ans = int((high + low)/2)
  18. print ("Is your secret number "+ str(ans) + "?")
  19. 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.")
  20.  
  21.  
  22.  
  23. elif var == 'l':
  24. low = ans
  25. ans = int((high + low)/2)
  26. print ("Is your secret number "+ str(ans) + "?")
  27. 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.")
  28.  
  29.  
  30.  
  31. elif var == 'c':
  32. print ("Game over. Your secret number was: " + str(ans))
  33. break
  34. else:
  35. print('Sorry, I did not understand your input.')
  36. 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.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement