student_scores = [75, 84, 66, 99, 51, 65]
def get_grade_stats(scores):
#calculate the arithmetic mean
mean = sum(scores)/len(scores)
#calculate the standard deviation
tmp = 0
for score in scores:
tmp += (score - mean ) **2
std_dev = (tmp/len(scores)) **0.5
#Package and return average, standard deciation in a tuple
return mean, std_dev
# unpack tuple
average, standard_deviation = get_grade_stats(student_scores)
print(f'Average score: {average}')
print(f'Standard deviation: {standard_deviation}')
# the mean and standard deviation of a set of student test scores.
# The statement return mean, std_dev creates and returns a tuple container. Recall that a tuple doesn't require parentheses around the contents,
# as the comma indicates a tuple should be created.
# An equivalent statement would have been return (mean, std_dev). The outputs could also have been returned in a list, as in return [mean, std_dev]
To embed this project on your website, copy the following code and paste it into your website's HTML: