Advertisement
Guest User

Computer Number Guessing Game

a guest
May 10th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # Program where the computer guesses a number between 1 and 100
  2. # The user tells the computer if it guesses too high or too low.
  3.  
  4.  
  5. import random
  6. random.seed
  7.  
  8. CompGuess =  random.randint(1,100)
  9. print "Pick a number."
  10. LowInt1 = 1
  11. HighInt1 = 100
  12. running = True
  13. while running == True:
  14.     print CompGuess
  15.     UserResp = raw_input("Was I right? H/L/Y: ")
  16.     if UserResp == "H":
  17.         HighInt1 = CompGuess
  18.         CompGuess = random.randint(LowInt1, HighInt1)
  19.         print CompGuess
  20.     if UserResp == "L":
  21.         LowInt1 = CompGuess
  22.         CompGuess = random.randint(LowInt1, HighInt1)
  23.         print CompGuess
  24.     if UserResp == "Y":
  25.         print "Hurrah! :3"
  26.         running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement