Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, August 31, 2019

Codecademy Learn Statistics With Python Variance Exercise 3/6


# Sample Solution
import numpy as np

grades = [88, 82, 85, 84, 90]
mean = np.mean(grades)

difference_one = 88 - mean
difference_two = 82 - mean
difference_three = 85 - mean
difference_four = 84 - mean
difference_five = 90 - mean

# manually check values and add
print(str(format(difference_one, "f")))
print(str(format(difference_two, "f")))
print(str(format(difference_three, "f")))
print(str(format(difference_four, "f")))
print(str(format(difference_five, "f")))

#Part 1: Sum the differences
difference_sum = (difference_one + difference_two + difference_three + difference_four + difference_five)

#Part 2: Average the differences
average_difference = difference_sum / 5

#IGNORE CODE BELOW HERE
print("The sum of the differences is " + str(format(difference_sum, "f")))
print("The average difference is " + str(format(average_difference, "f")))

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts