-
-
Save jsbain/195eb18e706736d6d020 to your computer and use it in GitHub Desktop.
riddler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from threading import Thread | |
import threading,time | |
class timer_thread(Thread): | |
def __init__(self,timeleft=30.): | |
Thread.__init__(self) | |
self.timeleft=timeleft | |
self._abort=False | |
def run(self): | |
while self.timeleft>0: | |
print self.timeleft | |
time.sleep(1.0) | |
self.timeleft-=1. | |
if self._abort: | |
return | |
print 'YOU LOSE' | |
def abort(self): | |
self._abort=True | |
def addtime(self): | |
self.timeleft+=10.0 | |
import random | |
def main(): | |
riddles=[['what have i got in my pocket','ring'], | |
['what has four legs in the morning, two legs in the day, threelegs in the evening?','man']] | |
t=timer_thread(30) | |
t.start() | |
while t.timeleft: | |
riddle=random.choice(riddles) | |
print riddle[0] | |
trial=raw_input() | |
if trial: | |
if trial==riddle[1]: | |
print 'correct!' | |
t.addtime() | |
else: | |
print 'Wrong!' | |
else: | |
t.abort() | |
t.join() | |
print 'aborted' | |
return | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment