# Statistics Example # Module: stats.py # Compute the mean, median, and # standard deviation of the men's # and women's heights in men.txt # and women.txt from statistics import * men_heights = [ ] fmen = open('men.txt', 'r') fmen.readline( ) fmen.readline( ) for line in fmen: heights = line.strip( ).split(' ') for ht in heights: men_heights.append(float(ht)) fmen.close( ) print("Number of observations:", len(men_heights)) print("Mean of men's heights", mean(men_heights)) print("Median of men's heights", median(men_heights)) print("SD of men's heights", round(stdev(men_heights), 2)) print( ) women_heights = [ ] fwomen = open('women.txt', 'r') fwomen.readline( ) fwomen.readline( ) for line in fwomen: heights = line.strip( ).split(' ') for ht in heights: women_heights.append(float(ht)) fwomen.close( ) print("Number of observations:", len(women_heights)) print("Mean of women's heights", mean(women_heights)) print("Median of women's heights", median(women_heights)) print("SD of women's heights", round(stdev(women_heights), 2))