Skip to content

Instantly share code, notes, and snippets.

@bcooksey
Created June 6, 2016 20:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcooksey/90fc3409ca63c652dcfd9769b7cd0314 to your computer and use it in GitHub Desktop.
Save bcooksey/90fc3409ca63c652dcfd9769b7cd0314 to your computer and use it in GitHub Desktop.
Python script to compute your average pace-per-mile from a total distance and a total time. See script for usage
#!/usr/bin/python
# Given a distance and time, computes your pace-per-mile:
# <distance in mi> - Total milage, in a format like `3.1` or `0.25`
# <time> - Total time. Allowed formats are `M:SS` or `H:MM:SS`
import sys
if len(sys.argv) == 1:
print 'Usage: <distance in mi> <time>'
sys.exit()
distance = sys.argv[1]
total_time = sys.argv[2]
if total_time.count(':') == 2:
hours, minutes, seconds = total_time.split(':')
else:
hours = 0
minutes, seconds = total_time.split(':')
total_seconds = (int(hours) * 3600) + (int(minutes) * 60) + int(seconds)
seconds_per_mile = float(total_seconds) / float(distance)
minutes_per_mile = int(seconds_per_mile / 60)
seconds_remainder = int(seconds_per_mile - (minutes_per_mile * 60))
print 'Avg. Pace of {}:{:0=2d}'.format(minutes_per_mile, seconds_remainder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment