This reads a csv file to get data on stations and miles. Use the starter code below and the linked csv file to solve this.
''' big exam question starter code implment your algorithm below complete the sections starting # TODO ''' # read file and clean up the data def getstationdata(): with open("stationlookupkingston.csv") as tfile: data = tfile.readlines() stationlist = [] for line in data: line = line.strip().split(',') line[1] = int(line[1]) # convert the miles to int stationlist.append(line) return stationlist #send back a 2d list ListOfStations = getstationdata() # list of stations and miles # intro for the user print(''' *********************************************** This section will simulate the card being read. We will assume journey ends at Kingston' Instead of IDs we will use station names *********************************************** ''') # TODO change start to an input from the user start = 'Barnes' #card being read miles = 0 # initialise miles # TODO add a for-loop to iterate through the elements in ListOfStations # TODO find the miles for start - remember it is a 2d list #TODO display the fare based on miles
Download the csv file for the above starter code.