Marathon Time Calculator

marathonIn this challenge you are going to write a Python script to help a marathoner predict the overall time they can complete a Marathon in (42km).

This estimation will be based on the runner’s pace which is the time they take to run 1km.

For instance:

  • Runner A runs 1km in 5:25 (5 minutes and 25 seconds)
  • Runner B, who is slower, runs 1km in 6:10 (6 minutes and 10 seconds)

Your Python script will:

  1. INPUT: Ask the runner for their pace (e.g. 5:25),
  2. PROCESS: Convert this input into a number of seconds: e.g. 5:25 = 5 * 60 + 25 = 325 seconds,
  3. PROCESS: Time this total by 42 as there are 42km in a Marathon,
  4. PROCESS: Convert this new total using the hh:mm:ss format. (e.g 3:47:30)
  5. OUTPUT: Display this new total on screen (using the hh:mm:ss format). (e.g 3:47:30)

Flowchart


The following flowchart describes the main steps of our flowchart based on the
Input > Process > Output model:
marathon-flowchart

Your Solution


Code your solution to this challenge:

Step by Step Solution:


The 5 steps described above are solved to help you complete this challenge step by step:

Step 1: Input the pace in the mm:ss format
Step 2: Convert this input into a number of seconds
Step 3: Time this total by 42 as there are 42km in a Marathon
Step 4: Convert this new total using the hh:mm:ss format
Step 5: Display this new total on screen
Note: To be 100% accurate you should time the pace by 42.195 instead of 42 as the exact length of a Marathon is 42km and 195 meters.

Testing


Now that you have implemented your solution you may want to test it by completing the following test plan: (this test plan is based on a length of 42km)

Test # Input Values Expected Output Actual Output
#1 Pace: 5:25 3:47:30
#2 Pace: 6:10 4:19:00
#3 Pace: 4:00 2:48:00
#4 Pace: 2:55 (Close to World Record) 2:02:30
Share Button
Posted in Computer Science, Python - Intermediate, Python Challenges Tagged with: , , ,

Our Latest Book