Part of the Whole


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

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


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

students = [lloyd, alice, tyler]


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

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


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:
    return average(results)

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


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


You're welcome.

Have fun coding! :slight_smile:


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


Pleas could you be more specific. Code & Error.

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


whats wrong with you I think your crazy


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


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


Not at all.

No intention at that.

Have fun coding! :slight_smile:


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


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



Please could you post your code and the issue.

Thank you! :slight_smile:


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


My apologies.

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

I want to help! :slight_smile:


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