Created
January 1, 2023 13:30
-
-
Save geraintwhite/f54b5dcaf162bf3f4c5d1c3b5934ed0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_turnaround(boat_speed, run_speed, distance): | |
return distance * (1 + boat_speed / run_speed) / 2 | |
def get_input(prompt, default): | |
try: | |
return float(input(prompt)) | |
except: | |
return default | |
def convert_pace(pace, default): | |
try: | |
mins, secs = map(float, pace.split(':')) | |
return 3600 / (60 * mins + secs) | |
except: | |
return default | |
def main(): | |
boat_speed = get_input('Boat speed (kph, default 5.0): ', 5.0) | |
run_speed = convert_pace(input('Run pace (min/km, default 5:00): '), 12.0) | |
distance = get_input('Desired distance (km, default 10.0): ', 10.0) | |
turnaround = find_turnaround(boat_speed, run_speed, distance) | |
print( | |
'Turn around after {:.1f}km to run a total {:.1f}km at {:.1f}kph if the boat is going {:.1f}kph' | |
.format(turnaround, distance, run_speed, boat_speed) | |
) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment