"""

John Rachlin
DS 2000: Intro to Programming with Data

Filename: exercise.py

Description: An example of reading from a file

Our input data (one value per line) is formatted with
seven lines each containing one value:
    - info about the run (string)
    - distance of run in km (float)
    - minutes run (int)
    - seconds run (int)
    - total steps (int)

"""


def main():

    # Get name of data file from user
    filename = input("What is the name of your exercise?: ")
    filename = filename + ".dat"

    # Open and read the file
    with open(filename, "r") as infile:
        info = infile.readline().strip()  # strip removes trailing newline
        distance_km = float(infile.readline())
        time_min = int(infile.readline())
        time_sec = int(infile.readline())
        steps = int(infile.readline())

    # Output the raw data for test purposes
    print("Information about my run:")
    print(info, distance_km, time_min, time_sec, steps,"\n")

    # Now let's do some calculations!

    # Compute pace in minutes per mile
    distance_mi = distance_km * 0.62
    total_time = time_min + time_sec / 60
    pace = total_time / distance_mi
    print("Pace [min/mi]           : ", round(pace, 2))

    # Compute stride length [inches / step]
    distance_in = distance_km * 1000 * 100 / 2.54
    stride = distance_in / steps
    print("Stride Length [in/step] : ", round(stride, 2))

    # Compute cadence [steps per minute]
    cadence = steps / total_time
    print("Cadence [steps/min]     : ", round(cadence, 2))


main()
