Advertisement
here2share

# timer4raw_input.py ZZZ

Jul 14th, 2016
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. # timer4raw_input.py
  2. from threading import Timer as tdi
  3. import time
  4. import os
  5.  
  6. def cv(): pass
  7. cv.yn=0
  8. def cls():
  9.     os.system('cls' if os.name == 'nt' else 'clear')
  10. #
  11. def goto(s):
  12.     if cv.yn:
  13.         if s.lower() in ('n','no'):
  14.             os._exit(1)
  15.         time.sleep(2)
  16.     else:
  17.         if "python" in s.lower():
  18.             message = "Woohoo, you did it... you wrote 'python' within 6 seconds! ... [ %s ]" % s
  19.         else:
  20.             message = "Failed! You did not write 'python' within 6 seconds... [ %s ]" % s
  21.         exit(message)
  22.  
  23. def ask():
  24.     t=tdi(6.0, restart)
  25.     t.start()
  26.     cls()
  27.     cv.yn=0
  28.     print "Type 'python' in 6 seconds:",
  29.     s = raw_input('')[:-1]
  30.     t.cancel()
  31.     goto(s)
  32.     ask()
  33. #
  34. def exit(msg):
  35.     cv.yn=1
  36.     print msg, "\nRestart? [y/n]:",
  37.     s=raw_input('')[:-1]
  38.     goto(s)
  39.     time.sleep(1)
  40. #
  41. def restart():
  42.     if not cv.yn:
  43.         exit("\nTime is up! You have failed")
  44. #
  45. ask()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement