Part of the Whole- feels correct still struck


#1

https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/4?curriculum_id=4f89dab3d788890003000096


#2

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


#3

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".


#4

I did changes still getting errors


#5

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


#6

i corrected that now new error is coming


#7

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


#8

i really confused it can u show the correct code?


#9

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?


#10


#11

try this:

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


#12

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


#13

still it's showing error msg...


#14

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:
   results.append(get_average(student))

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.


#15

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" 
    else:
        return "F"
      
print  get_letter_grade(get_average(lloyd)) 

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

#16

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


#17

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


#18

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


#19

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


#20