Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. # Computer Guesses Number
  2.  
  3. import random
  4.  
  5. # first whiletrue for the "replay" mechanic
  6. while True:
  7.     low = 1
  8.     high = 100
  9.     print("I will guess your number from 1 to 100 because I am SMART computer!")
  10.     input("Press Enter when ready.")
  11. # second whiletrue for the reguessing mechanic
  12.     while True:
  13.         guess = random.randint(low, high)
  14.         print("\nI guess the number", guess, ".")
  15.         while True:
  16. # third whiletrue to reask the question when user types something other than
  17. # 'higher', 'lower', and 'correct'
  18.             result = input("Is your number 'higher', 'lower', or is this 'correct'? ")
  19.             if result == "higher":
  20.                 low = guess + 1
  21.                 break
  22.             elif result == "lower":
  23.                 high = guess - 1
  24.                 break
  25.             elif result == "correct":
  26.                 print("I am smrt.  :3  \n")
  27.                 break
  28.             else:
  29.                 continue
  30.         if result != "correct":
  31.             continue
  32.         else:
  33.             break
  34.     retry = input("Press 'r' to play again, or press any other key to exit.")
  35.     if retry == "r" or retry == "R":
  36.         continue
  37.     else:
  38.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement