gaussiantable.py


Below is the syntax highlighted version of gaussiantable.py from §2.2 Modules and Clients.


#-----------------------------------------------------------------------
# gaussiantable.py
#-----------------------------------------------------------------------

import sys
import stdio
import gaussian

#-----------------------------------------------------------------------

# Accept a mean and standard deviation as command-line arguments.
# Write to standard output a table of the percentage of students
# scoring below certain scores on the SAT, assuming the test scores
# obey a Gaussian  distribution with the given mean and standard
# deviation.

mu = float(sys.argv[1])
sigma = float(sys.argv[2])

for score in range(400, 1600+1, 100):
    percent = gaussian.cdf(score, mu, sigma)
    stdio.writef('%4d  %.4f\n', score, percent)
 
#-----------------------------------------------------------------------

# python gaussiantable.py 1019 209
#  400  0.0015
#  500  0.0065
#  600  0.0225
#  700  0.0635
#  800  0.1474
#  900  0.2845
# 1000  0.4638
# 1100  0.6508
# 1200  0.8068
# 1300  0.9106
# 1400  0.9658
# 1500  0.9893
# 1600  0.9973


Copyright © 2000–2015, Robert Sedgewick, Kevin Wayne, and Robert Dondero.
Last updated: Fri Oct 20 20:45:16 EDT 2017.