I Review

i. Let’s look at those grades! 1/9

>Save and Submit!

ii. Print those grades 2/9

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def print_grades(grades): for i in grades: print i print print_grades(grades)

iii. Review 3/9

>Save and Submit!

II The Average Grade

i. The sum of scores 4/9

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def grades_sum(grades): result = 0 for x in grades: result += x return result print grades_sum(grades)

ii. Computing the Average 5/9

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def grades_sum(scores): result = 0 for x in scores: result = x + result return result print grades_sum(grades) def grades_average(grades): return grades_sum(grades)/float(len(grades)) print grades_average(grades)

iii. Review 6/9

>Save and Submit

III Do the Grades vary?

i. The Variance 7/9

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def print_grades(grades): for grade in grades: print grade def grades_sum(grades): total = 0 for grade in grades: total += grade return total def grades_average(grades): sum_of_grades = grades_sum(grades) average = sum_of_grades / float(len(grades)) return average def grades_variance(scores): average = grades_average(scores) variance = 0 for score in scores: variance += ((score - average)**2)/len(scores) return variance print grades_variance(grades)

ii. Standard Deviation 8/9

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def print_grades(grades): for grade in grades: print grade def grades_sum(grades): total = 0 for grade in grades: total += grade return total def grades_average(grades): sum_of_grades = grades_sum(grades) average = sum_of_grades / float(len(grades)) return average def grades_variance(scores): average = grades_average(scores) variance = 0 for score in scores: variance += ((score - average)**2)/len(scores) return variance print grades_variance(grades) var = grades_variance(grades) def grades_std_deviation(var): return var**0.5 print grades_std_deviation(var)

iii. Review 9/9

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def print_grades(grades): for grade in grades: print grade print print_grades(grades) def grades_sum(grades): total = 0 for grade in grades: total += grade return total print grades_sum(grades) def grades_average(grades): sum_of_grades = grades_sum(grades) average = sum_of_grades / float(len(grades)) return average print grades_average(grades) def grades_variance(scores): average = grades_average(scores) variance = 0 for score in scores: variance += ((score - average)**2)/len(scores) return variance print grades_variance(grades) var = grades_variance(grades) def grades_std_deviation(var): return var**0.5 print grades_std_deviation(var)

Advertisements