#!/usr/bin/env python # ----------------------------------------------------------------------------------- # # # Python macro for Applied Statistics 2017/18 exam, problem 4.1 on Women and Men. # # Author: Troels C. Petersen (NBI) # Email: petersen@nbi.dk # Date: 16th of January 2018 # # ----------------------------------------------------------------------------------- # data = [] with open( 'data_WomenAndMen.txt', 'r' ) as infile : header = infile.readline() # Read (and ignore) the first line, which is a header line! counter = 0 for line in infile: columns = line.strip().split() if (len(columns) == 6) : data.append([ float(columns[0]), float(columns[1]), float(columns[2]), float(columns[3]), float(columns[4]), int(columns[5]) ]) # Print some of the data as a sanity check: if (counter < 10) : print(" Height: {:5.3f} m Gender: {:1d}".format(data[counter][0], data[counter][5])) counter += 1 print(" The total number of data points read is: {:d}".format(counter))