Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # timer4raw_input.py
- from threading import Timer as tdi
- import time
- import os
- def cv(): pass
- cv.yn=0
- def cls():
- os.system('cls' if os.name == 'nt' else 'clear')
- #
- def goto(s):
- if cv.yn:
- if s.lower() in ('n','no'):
- os._exit(1)
- time.sleep(2)
- else:
- if "python" in s.lower():
- message = "Woohoo, you did it... you wrote 'python' within 6 seconds! ... [ %s ]" % s
- else:
- message = "Failed! You did not write 'python' within 6 seconds... [ %s ]" % s
- exit(message)
- def ask():
- t=tdi(6.0, restart)
- t.start()
- cls()
- cv.yn=0
- print "Type 'python' in 6 seconds:",
- s = raw_input('')[:-1]
- t.cancel()
- goto(s)
- ask()
- #
- def exit(msg):
- cv.yn=1
- print msg, "\nRestart? [y/n]:",
- s=raw_input('')[:-1]
- goto(s)
- time.sleep(1)
- #
- def restart():
- if not cv.yn:
- exit("\nTime is up! You have failed")
- #
- ask()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement