Skip to content

Instantly share code, notes, and snippets.

@BlackVikingPro
Created March 5, 2017 03:13
Show Gist options
  • Save BlackVikingPro/b1709f2c1933a003c7e00a7f323acf56 to your computer and use it in GitHub Desktop.
Save BlackVikingPro/b1709f2c1933a003c7e00a7f323acf56 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
""" !- Stopwatch.py ~ By: Willy Fox - @BlackVikingPro -! """
import sys, time
def stopwatch():
min = 0
sec = 0
print("")
while True:
if len(str(min)) == 1 and len(str(sec)) == 1:
sys.stdout.write("\r 0%s mins - 0%s secs" % (min, sec))
pass
elif len(str(min)) == 1 and len(str(sec)) == 2:
sys.stdout.write("\r 0%s mins - %s secs" % (min, sec))
pass
elif len(str(min)) == 2 and len(str(sec)) == 1:
sys.stdout.write("\r %s mins - 0%s secs" % (min, sec))
pass
elif len(str(min)) == 2 and len(str(sec)) == 2:
sys.stdout.write("\r %s mins - %s secs" % (min, sec))
pass
sys.stdout.flush() # flush standard output
sec = sec + 1
if sec == 60:
sec = 0
min = min + 1
pass
time.sleep(1) # 1 second(s))
pass
if __name__ == "__main__":
try:
stopwatch()
except KeyboardInterrupt:
sys.exit("\n\n Come back for more fun ~ Willy Fox - @BlackVikingPro")
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment