Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import os, random, sys, time as t, multiprocessing as mp
- def countdown_less(x):
- color = 40
- print '\nCounting...'
- os.system('clear')
- for z in xrange(x, 0, -1):
- color = random.randint(40, 54) if color >= 54 else color
- print "\033[%dm%d second(s)" % (color, z)
- t.sleep(1)
- os.system('clear')
- color += 1
- else:
- print "\033[9mCountdown finished."
- t.sleep(0.7)
- os.system("clear")
- def countdown_more(x):
- color = 40
- os.system('clear')
- if x != 0:
- try:
- for z in xrange(0, x):
- color = random.randint(40, 54) if color >= 54 else color
- print "\033[%dm%d second(s)" % (color, z+1)
- t.sleep(1)
- os.system('clear')
- color += 1
- else:
- print "\033[9mCountdown finished."
- t.sleep(0.7)
- os.system("clear")
- except KeyboardInterrupt:
- os.system('clear')
- print "\033[33mParado!\n"
- t.sleep(0.7)
- os.syste('clear')
- sys.exit(0)
- except e:
- os.system('clear')
- sys.stdout.write("exception:", e)
- else:
- z, color = 1, 40
- while True:
- try:
- color = random.randint(40, 54) if color >= 54 else color
- print "\033[%dm%d second(s)" % (color, z)
- t.sleep(1)
- os.system('clear')
- color += 1
- z += 1
- except KeyboardInterrupt:
- os.system('clear')
- print "\033[33mParado!\n"
- t.sleep(0.7)
- os.system("clear")
- sys.exit(0)
- except e:
- os.system('clear')
- sys.stdout.write("exception:", e)
- def menu():
- print "[1] Stopwatch\n[2] Countdown\n\nEnter with the number: "
- def main():
- menu()
- inp = int(raw_input())
- if inp == 1:
- print "\nTime (in seconds): "
- time = int(raw_input())
- x = mp.Pool(processes=2)
- x.apply_async(countdown_less(time))
- elif inp == 2:
- print "\nTime (in seconds): "
- time = int(raw_input())
- x = mp.Pool(processes=2)
- x.apply_async(countdown_more(time))
- else:
- print("out of control... exiting..\n")
- sys.exit(0)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment