Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Simple Guess what number I'm thinking of game.
- Note: uses espeak to vocalize """
- from random import randint
- import subprocess
- import time
- import os as os
- def execute_unix(inputcommand):
- p = subprocess.Popen(inputcommand, stdout=subprocess.PIPE, shell=True)
- (output, err) = p.communicate()
- return output
- def guessingGame():
- solution = randint(1,100)
- c = "I am thinking of a number between 1 and 100.\nYou have one minute to try and guess it."
- b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
- print c
- execute_unix(b)
- a=time.time()
- while 1:
- guess = int(raw_input('Enter guess >'))
- os.system('clear')
- if (time.time()-a)>60:
- c = "Times up, Sucker.\nThe answer was %s" % solution
- b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
- print c
- execute_unix(b)
- break
- if guess==solution:
- c = "Hurrah. You guessed correctly"
- b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
- print c
- execute_unix(b)
- break
- elif guess>solution:
- c = "Guess lower"
- b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
- print c
- execute_unix(b)
- elif guess<solution:
- c = " Guess higher"
- b = 'espeak -ven+f3 -k5 -s150 --punct="<characters>" "%s" 2>>/dev/null' % c
- print c
- execute_unix(b)
Advertisement
Add Comment
Please, Sign In to add comment