Part of the Whole


#1



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

Oops, try again. get_class_average([alice]) resulted in an error: global name 'result' is not defined


We want to calculate the class average grade.
I removed the PRINT GET_LETTER_GRADE(GET_AVERAGE(LLOYD)) part from earlier in the course, because we don't want that printed (am i correct?), tho this wont solve the code.

So anyone see what's wrong?

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 = float(sum(numbers))
    result = total / float(len(numbers))
    return result
    
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 >= 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))

def get_class_average(students):
    results = []
    for student in students:
        result.append(get_average(student))
    return average(results)


#2

It can't see the students list you are looping for here:

students = [lloyd, alice, tyler]


#3

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

Like this? i still get the same error message..


#4

Na... At the bottom of you last function code or maybe after the dictionaries you created.

Like this:

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

students = [lloyd, alice, tyler]
print get_class_average(students)
print get_letter_grade(get_class_average(students))

#5

Thanks for the help
forgot an S at results.append(get_average(student))


#6

You're welcome.

Have fun coding! :slight_smile:


#7

doesn't work why its not helping and its not working


#8

Pleas could you be more specific. Code & Error.

You really should have opened a new post. :slight_smile:


#10

whats wrong with you I think your crazy


#11

so in other words you are telling me to shut up right :grin:


#12

yeh the person is!! coz your stupid!!!!!


#13

Not at all.

No intention at that.

Have fun coding! :slight_smile:


#14

just say the truth i know you where, shes just stupid!! well anyways tell me the right code!!!!!!!!!!!!!!!!!!


#15

why is she so annoying! gosh, something might be wrong with her head well anyways get well soon :joy:


#16

Okay.

Please could you post your code and the issue.

Thank you! :slight_smile:


#17

Just tell me what to write for it gosh is that so hard


#18

My apologies.

Please what exercise, your code and error. I'm a bit lost out.

I want to help! :slight_smile:


#19

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.