Advertisement
KaySawbridge

Guess the number game

Jul 20th, 2020
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. ## Guessing Game
  2.  
  3. max = 100
  4. min = 0
  5.  
  6. print("Think of a number between 1 and 100")
  7.  
  8.  
  9. middle = int((max + min)/2)
  10. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  11. if answer == "H":
  12.   min = middle
  13. elif answer == "L":
  14.   max = middle
  15. else:
  16.   print("Your number is {}, it took me 1 guess".format(middle))
  17.   quit()
  18.  
  19. middle = int((max + min)/2)
  20. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  21. if answer == "H":
  22.   min = middle
  23. elif answer == "L":
  24.   max = middle
  25. else:
  26.   print("Your number is {}, it took me 2 guesses".format(middle))
  27.   quit()
  28.  
  29. middle = int((max + min)/2)
  30. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  31. if answer == "H":
  32.   min = middle
  33. elif answer == "L":
  34.   max = middle
  35. else:
  36.   print("Your number is {}, it took me 3 guesses".format(middle))
  37.   quit()
  38.  
  39. middle = int((max + min)/2)
  40. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  41. if answer == "H":
  42.   min = middle
  43. elif answer == "L":
  44.   max = middle
  45. else:
  46.   print("Your number is {}, it took me 4 guesses".format(middle))
  47.   quit()
  48.  
  49. middle = int((max + min)/2)
  50. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  51. if answer == "H":
  52.   min = middle
  53. elif answer == "L":
  54.   max = middle
  55. else:
  56.   print("Your number is {}, it took me 5 guesses".format(middle))
  57.   quit()
  58.  
  59. middle = int((max + min)/2)
  60. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  61. if answer == "H":
  62.   min = middle
  63. elif answer == "L":
  64.   max = middle
  65. else:
  66.   print("Your number is {}, it took me 6 guesses".format(middle))
  67.   quit()
  68.  
  69. middle = int((max + min)/2)
  70. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  71. if answer == "H":
  72.   min = middle
  73. elif answer == "L":
  74.   max = middle
  75. else:
  76.   print("Your number is {}, it took me 7 guesses".format(middle))
  77.   quit()
  78.  
  79. middle = int((max + min)/2)
  80. answer = input("Is your number [H]igher, [L]ower or the [S]ame as {}".format(middle)).upper()
  81. if answer == "H":
  82.   min = middle
  83. elif answer == "L":
  84.   max = middle
  85. else:
  86.   print("Your number is {}, it took me 8 guesses".format(middle))
  87.   quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement