Skip to content

Instantly share code, notes, and snippets.

@binh-bk
Last active November 5, 2024 05:48
Show Gist options
  • Save binh-bk/411379925a77ecbda92dc4496a431e6d to your computer and use it in GitHub Desktop.
Save binh-bk/411379925a77ecbda92dc4496a431e6d to your computer and use it in GitHub Desktop.
convert running pace in minutes per mile to minutes per km and distance of mile to km
#! /usr/python3
def pace_mi2km(minute_per_mile: str):
# minute_a_mile: str, for example 10:19 (10minutes 19 seconds per mile)
# return a str of minutes per km
mile = 1.60934
# convert pace mm:ss to second
minute, second = minute_per_mile.split(':')[0].strip(), minute_per_mile.split(':')[1].strip()
# print(minute, second)
seconds = int(minute)*60 + int(second)
pace_in_km = seconds / mile
# convert back to mm:ss format
minute = int(pace_in_km//60)
second = int(pace_in_km%60)
# minute: second per km
return f"{str(minute).zfill(2)}:{str(second).zfill(2)}"
def mile2km(mile: float):
mile_km = 1.60934
return round(mile * mile_km,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment