title: Getting an average in a function in Python
body: <p>I am trying to learn Python and I am stuck. Everything went fine until the last function which is the:     </p>
  
  <pre><code>def get_class_average(students): 
  </code></pre>
  
  <p>up to that point it all works fine, but there, at the last function, I can't figure out how to make it work. I am trying to get the averages for each student, then calculate the averages of those averages, in other words the "class average" So, I only would like to know the answer for the last function without changing any of the functions before the last one:</p>
  
  <pre><code>lloyd = {
      "name": "Lloyd",
      "homework": [90.0, 97.0, 75.0, 92.0],
      "quizzes": [88.0, 40.0, 94.0],
      "tests": [75.0, 90.0]
  }
  alice = {
      "name": "Alice",
      "homework": [100.0, 92.0, 98.0, 100.0],
      "quizzes": [82.0, 83.0, 91.0],
      "tests": [89.0, 97.0]
  }
  tyler = {
      "name": "Tyler",
      "homework": [0.0, 87.0, 75.0, 22.0],
      "quizzes": [0.0, 75.0, 78.0],
      "tests": [100.0, 100.0]
  }
  
  
  
  def average(numbers):
         total = sum(numbers)
         return float(total) / len(numbers)
  
  
  def get_average(student):
         homework = average(student["homework"]) 
         quizzes = average(student["quizzes"]) 
         tests = average(student["tests"]) 
         return 0.1 * average(student["homework"]) + 0.3 * average(student["quizzes"])    +     0.6 * average(student["tests"])
  
  def get_letter_grade(score):
         if score &gt;= 90:
                return "A"
         elif score &gt;= 80:
                return "B"         
         elif score &gt;= 70:
                return "C"
         elif score &gt;= 60:
                return "D"
         else:
                return "F"
  
  def get_class_average(students):
         results = []
         for student in results:
                get_average(student)
                results.append(student)
                average(student)
                return results
  
  students = [lloyd,alice,tyler]
  
  print get_class_average(students)
  </code></pre>
  
  <p>I finally figured out the solution for this one. So, I just want to post the corrected code here below for the last function, get_class_average(students). Now it works:</p>
  
  <pre><code>def get_class_average(students):
         results = []
         for each in students:
                studentavg = float(get_average(each))
                results.append(studentavg)
         return average(results)
  
  students = [lloyd,alice,tyler]
  
  print get_class_average(students)
  </code></pre>