lolamontes69

guessingGame.py Friday night entertainment

Oct 19th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. """ Simple Guess what number I'm thinking of game.
  2.    Note: uses espeak to vocalize """
  3.  
  4. from random import randint
  5. import subprocess
  6. import time
  7. import os as os
  8.  
  9. def execute_unix(inputcommand):
  10.    p = subprocess.Popen(inputcommand, stdout=subprocess.PIPE, shell=True)
  11.    (output, err) = p.communicate()
  12.    return output
  13.  
  14. def guessingGame():
  15.     solution = randint(1,100)
  16.     c = "I am thinking of a number between 1 and 100.\nYou have one minute to try and guess it."
  17.     b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  18.     print c
  19.     execute_unix(b)
  20.     a=time.time()
  21.     while 1:
  22.         guess = int(raw_input('Enter guess >'))
  23.         os.system('clear')
  24.         if (time.time()-a)>60:
  25.             c = "Times up, Sucker.\nThe answer was %s" % solution
  26.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  27.             print c
  28.             execute_unix(b)
  29.             break
  30.         if guess==solution:
  31.             c = "Hurrah. You guessed correctly"
  32.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  33.             print c
  34.             execute_unix(b)
  35.             break
  36.         elif guess>solution:
  37.             c = "Guess lower"
  38.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  39.             print c
  40.             execute_unix(b)
  41.         elif guess<solution:
  42.             c = " Guess higher"
  43.             b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
  44.             print c
  45.             execute_unix(b)
Advertisement
Add Comment
Please, Sign In to add comment