1. 程式人生 > >python list示例

python list示例

span iat urn color pre float inpu for +=

 1 grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
 2 
 3 def print_grades(grades_input):
 4   for grade in grades_input:
 5     print grade
 6 print_grades(grades)
 7 def grades_sum(scores):
 8   total = 0
 9   for score in scores: 
10     total += score
11   return total
12 print grades_sum(grades)
13 def grades_average(grades_input): 14 sum_of_grades = grades_sum(grades_input) 15 average = sum_of_grades / float(len(grades_input)) 16 return average 17 print grades_average(grades) 18 def grades_variance(scores): 19 average=grades_average(scores) 20 variance=0 21 for score in scores: 22
variance+=(average-score)**2 23 return variance/float(len(scores)) 24 25 print grades_variance(grades) 26 27 def grades_std_deviation(variance): 28 return variance**0.5 29 30 variance=grades_variance(grades) 31 32 print grades_std_deviation(variance)

python list示例