''' DS2000 Spring 2023 Sample code from class - reading in multiple values from one line into a list. Practice with: 1. slicing 2. ranges 3. list comprehension 4. plotting ''' RUNNER_FILE = "laney_garmin.txt" def main(): # Gather data - read the one line from the file with open(RUNNER_FILE, "r") as infile: line = infile.readline() # Sanity-check print, what's in the variable? print("Just did readline()...") print(line) # Turn the string into a list runner = line.split() # Sanity-check print, did we make a list? print("\nJust did split(), do we have a list?...") print(runner) # Slicing team! How can I get a list without # my name in it? runner_data = runner[2:] # Sanity-check print, this should have everything BUT # the name print("\nJust did some slicing, do we skip the first two?...") print(runner_data) # Grab the first two values to create a string runner_name = runner[0] + " " + runner[1] # Sanity check, did we get the runner's name? print("\nRunner's name:", runner_name) # Range team! How can I create list of JUST # the distances values, and skip the dates? distances = [] for i in range(1, len(runner_data), 2): distances.append(runner_data[i]) # Sanity check, do we have a list of JUST distances? print("\nHopefully these are just dist, not dates...") print(distances) # List comprehension team! How can I turn my list of # strings into a list of floats? distances = [float(num) for num in distances] # Sanity check, do we have a list of distances that # is actually floats? print("\nThese are distances, and they are not strings...") print(distances) # Do some computations on the list avg_mileage = sum(distances) / len(distances) print("Average mileage:", avg_mileage) max_mileage = max(distances) print("Max long run:", max_mileage) main()