Part of the Whole- feels correct still struck



In the for loop, shouldn't you get_average for each student, not all of them at once?


When you call the get_average function, the argument should be student (singular).
If you look at your for/in loop, you are calling this function get_average for each "student" in the list called "students".


I did changes still getting errors


Your students list shouldn't be in the function like statement in the error explained to you.


i corrected that now new error is coming


I told you to take it out of the function, I'll let you figure out what you didn't do.


i really confused it can u show the correct code?


students = [lloyd, alice, tyler]
def  get_class_average(students):
    #rest of code should be the same

Here I took out the students list you had from the function. That's because you can't use a list inside your function as part of an outside source. See what I mean?



try this:

def get_class_average(students):
for student in students:
return average(results);


watch out for the white spaces i.e. indentation, adjust accordingly.


still it's showing error msg...


your for loop:

for student in student:

why not:

for student in students:

students is a list holding your students, by looping over it, student contains the students in turn (lloyd, alice, tyler) so then you can just append the average of student:

for student in students:

then you put return at the same indent level as the for loop, so the whole loop can run. If you are still stuck after this, copy paste your whole code to the forum so we can actually run it.


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):

    total = sum (numbers)
    total = float (total)
    total = total / len (numbers)
    return total

def get_average(student):
    homework = average(student['homework'])
    quizzes = average(student['quizzes'])
    tests = average(student['tests'])
    return (homework * 0.1) + (quizzes * 0.3) + (tests * 0.6)
def get_letter_grade(score):
    if score >= 90:
        return "A"
    elif score >= 80:
        return "B" 
    elif score >= 70:
        return "C" 
    elif score >= 60:
        return "D" 
        return "F"
print  get_letter_grade(get_average(lloyd)) 

students = [lloyd,alice,tyler]
def get_class_average(students):
    results = []
    for student in students:
        return average(results)


you didn't change the indent of return average(results) like i suggested, a function ends the moment a return keyword is reached, which is currently happening in the first run of the loop, place return outside the loop, so the whole loop can run


my goodness it's working after a long struggle thx a lot :slight_smile:


do you also understand why it is working? That is more important


yeap understood it. how can i marked this question as solved?