renix1

Sla, mas é legal, py 2.x

Dec 18th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. import os, random, sys, time as t, multiprocessing as mp
  4.  
  5. def countdown_less(x):
  6.     color = 40
  7.     print '\nCounting...'
  8.     os.system('clear')
  9.     for z in xrange(x, 0, -1):
  10.         color = random.randint(40, 54) if color >= 54 else color
  11.         print "\033[%dm%d second(s)" % (color, z)
  12.         t.sleep(1)
  13.         os.system('clear')
  14.         color += 1
  15.     else:
  16.         print "\033[9mCountdown finished."
  17.         t.sleep(0.7)
  18.         os.system("clear")
  19.  
  20. def countdown_more(x):
  21.     color = 40
  22.     os.system('clear')
  23.     if x != 0:
  24.         try:
  25.             for z in xrange(0, x):
  26.                 color = random.randint(40, 54) if color >= 54 else color
  27.                 print "\033[%dm%d second(s)" % (color, z+1)
  28.                 t.sleep(1)
  29.                 os.system('clear')
  30.                 color += 1
  31.             else:
  32.                 print "\033[9mCountdown finished."
  33.                 t.sleep(0.7)
  34.                 os.system("clear")
  35.         except KeyboardInterrupt:
  36.             os.system('clear')
  37.             print "\033[33mParado!\n"
  38.             t.sleep(0.7)
  39.             os.syste('clear')
  40.             sys.exit(0)
  41.         except e:
  42.             os.system('clear')
  43.             sys.stdout.write("exception:", e)
  44.     else:
  45.         z, color = 1, 40
  46.         while True:
  47.             try:
  48.                 color = random.randint(40, 54) if color >= 54 else color
  49.                 print "\033[%dm%d second(s)" % (color, z)
  50.                 t.sleep(1)
  51.                 os.system('clear')
  52.                 color += 1
  53.                 z += 1
  54.             except KeyboardInterrupt:
  55.                 os.system('clear')
  56.                 print "\033[33mParado!\n"
  57.                 t.sleep(0.7)
  58.                 os.system("clear")
  59.                 sys.exit(0)
  60.             except e:
  61.                 os.system('clear')
  62.                 sys.stdout.write("exception:", e)
  63.  
  64. def menu():
  65.     print "[1] Stopwatch\n[2] Countdown\n\nEnter with the number: "
  66.  
  67. def main():
  68.     menu()
  69.     inp = int(raw_input())
  70.     if inp == 1:
  71.         print "\nTime (in seconds): "
  72.         time = int(raw_input())
  73.         x = mp.Pool(processes=2)
  74.         x.apply_async(countdown_less(time))
  75.     elif inp == 2:
  76.         print "\nTime (in seconds): "
  77.         time = int(raw_input())
  78.         x = mp.Pool(processes=2)
  79.         x.apply_async(countdown_more(time))
  80.     else:
  81.         print("out of control... exiting..\n")
  82.         sys.exit(0)
  83.  
  84. if __name__ == '__main__':
  85.     main()
Advertisement
Add Comment
Please, Sign In to add comment