Help needed in proceeding to the next level


I am currently learning python on and am not able to proceed to the next level. Please help me! This is the question that has posed me with:

  1. Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students.
  2. First, make an empty list called results.
  3. For each student item in the class list, calculate get_average(student) and then call results.append() with that result.
  4. Finally, return the result of calling average() with results.

And this is the code I have written: -

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]

Add your function below!

def average(numbers):
return total/len(numbers)

def get_average(student):
return (0.1*homework)+(0.3*quizzes)+(0.6*tests)

def get_letter_grade(score):
return 'A'
return 'B'
return 'C'
return 'D'
return 'F'


*** results=[]
def get_class_average(students):
for student in students:
return average(results) ***

When I try to execute the code, it gives me this error message: "Oops, try again. Make sure you have defined get_class_average"

I am having a problem in the part of the code enclosed between the two '***'s. I am not very sure about the syntax. Could you please check it? Also I feel there is some problem with the question as the function get_average accepts dictionaries as arguments but the questions is asking me to do something else. I am confused and am not able to proceed further.


Hey @prabhatikavij,

Try to put results inside of your function body...


Thank you so much @bartholomewallen for your help! I tried doing it but it doesn't work.


@prabhatikavij you should make these following changes: 1. In the instructions they have asked you to put empty results[] after defining the function it will be like this
def get_class_average(students):
results = []
for student in students:
return average(results)

  1. previously they would have asked to calculate the grade and print it out for each student, not just lloyd. so you have to simply put it as print for each student
    print get_letter_grade(get_average(student)) or put it for each of the student individually like so:

print get_letter_grade(get_average(lloyd))
print get_letter_grade(get_average(alice))
print get_letter_grade(get_average(tyler))

Hope this solves for you ! I recently went through this..Good luck!

@bartholomewallen helped me out ! lol


Thank you so much for your replies, @bartholomewallen and @asher3667. I have finally managed to find the error in my code and process to the next level. The error in my code was that the line 'results=[]' should have been inside the function body (as suggested by both of you!) and there was a silly mistake too! There was a problem with the indentation of the function.

Thank you so much for your replies. I really appreciate the fact that you gave your time to answer my doubt.