Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Computer Number Guessing Game

By: a guest on May 10th, 2012  |  syntax: Python  |  size: 0.63 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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