8. Part of the whole


#1



student becomes the teacher. part 8. part of the whole


Error:
Oops, try again. get_class_average([alice]) resulted in an error: 'list' object has no attribute 'apppend'

The python 'list' object does have the attribute 'append' though, right? This is how append works on lists, right: This error message reads to me like a javascript message saying "hey, array doesn't have a push() method."


What I expected:
* I expect the TDD variable students to be passed into function get_class_average().
* I expect an empty list called results to be defined.
* I expect a for loop to cycle through the list called students which the function was called with.
* I expect that for each element in students get_average() will be run, and this will be appended into the above list called results.
* When the loop is complete I expect the average function to be run on the completed results list and returned.


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 = float(sum(numbers))
    return total/len(numbers)
    
def get_average(student):
    return average(student['homework']) * .1 + average(student['quizzes']) * .3 + average(student['tests']) * .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'

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


#2

Note the spelling...


#3

1) You're awesome.
2) That's really embarrassing.

Thanks, man!


#4

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