Define get_class_average?


#1




Oops, try again. Make sure you have defined get_class_average

Also having a hard time getting my head around the for student in students line.


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 and score < 90:
        return "B"
    elif score >= 70 and score < 80:
        return "C"
    elif score >= 60 and score < 70:
        return "D"
    else:
        return "F"
        
    print get_letter_grade(get_average(loyd))
    
    def get_class_average(students):
        results = []
        for student in students:
            a = get_average(student)
            results = results.append()
        return average(results)


#2

this is all indented to far, making it inside of the get_letter_grade function. you need to unindent it so that print get_letter_grade(get_average(loyd)) and def get_class_average(students): are on the same indent level ofdef get_letter_grade(score):

also, in the line print get_letter_grade(get_average(loyd)), you misspelled loyd, it should be lloyd.


#3

Ty for the reply kyleaw.

I'm getting another error that is: "Oops, try again. get_class_average([alice]) resulted in an error: append() takes exactly one argument (0 given)". Any idea whats wrong?

Here's my code:

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 = 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 and score < 90:
return "B"
elif score >= 70 and score < 80:
return "C"
elif score >= 60 and score < 70:
return "D"
else:
return "F"

print get_letter_grade(get_average(lloyd))

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


#4

The error message means that you're not actually appending anything. Append is like a function, (though not exactly), it takes an argument in the parenthesis. Instead of setting results = results.append(), you just need to append to results. Setting it equal to results is changing what the results variable is.
It would actually just be results.append(a) because you want to append each students average (the variable a) to the results list. Hope this helps!


#5

thx alot, been stuck on this exercise for quite a while :wink:


#6

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