Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming language: Python Write a function, grade_histogram(t,mu,sigma,n), wh

ID: 3726998 • Letter: P

Question

Programming language: Python

Write a function, grade_histogram(t,mu,sigma,n), which uses the turtle module to
make a histogram for quiz score data for n = 100 students. First, create the data using
gauss(mu,sigma), from the random module. mu is the average and sigma is the
standard deviation of the scores and is a measure of the spread of the data scores.
When the quiz data is generated, check to make sure that each quiz score is between 0
and 100, inclusive. Put the data into a list. Take the data you generated with the
specified mean and standard deviation & make a histogram of the number of A’s, B’s,
C’s, D’s and F’s, according to the following rubric:


A: 95 <= score <= 100


B: 85 <= score < 95


C: 75 <= score < 85


D: 65 <= score < 75


F: score < 65


Use appropriate helper functions to make your code easy to write and easy to read.


Scale the histogram height so the maximum height is 300 turtle steps. Your code
should have output like the sample shown below which uses 100 students with mu =
80 and sigma = 10, and which includes the labels shown on top of each of the
histogram bars. Note that the number of A’s, B’s, C’s, D’s and E’s must equal to n.


grade_histogram(alex,80,10,100)

Explanation / Answer

import matplotlib.pyplot as plt

import numpy as np

mu, sigma = 100, 15

x = mu + sigma * np.random.randn(10000)

bins = [0, 40, 60, 75, 90, 110, 125, 140, 160, 200]

hist, bins = np.histogram(x, bins=bins)

width = np.diff(bins)

center = (bins[:-1] + bins[1:]) / 2

fig, ax = plt.subplots(figsize=(8,3))

ax.bar(center, hist, align='center', width=width)

ax.set_xticks(bins)

fig.savefig("/tmp/out.png")

plt.show()