# input: name of file to read # output: list of all names in the file def read_name_list(file_name): names = [] name_file = open(file_name, "r") for line in name_file: line = line.strip() names.append(line) return names def read_temperature_data(file_name): temperatures = [] data_file = open(file_name, "r") burn_line = True for line in data_file: if burn_line: # if we know there is a header and we don't need to process it # we can burn the header (i.e., throw it away) burn_line = False # print(line) # this will show the header continue entry = line.split(",") temperatures.append(float(entry[1])) # format: date, max temperatureF, ... return temperatures # input: file name of weather data to read # output: average temp (float), high temp, low temp def statistics(file_name): temperatures = read_temperature_data(file_name) length = len(temperatures) total = sum(temperatures) return total / length, max(temperatures), min(temperatures) # return multiple values --> "tuple" print(statistics("weather.csv")) # notice, a relative path is used here # Can we specify a file with an absolute path? # If yes, why don't we use it here? # When can we use an absolute path?