8.Part of whole


#1



Hello,

I can't understand what is the problem (is it about the line--> total=float(total) or something else?) and what should I do


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


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

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return 0.1*homework + 0.3*quizzes + 0.6*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))

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


#2

@na2i ,

What are you trying to do within the get_class_average function, here?

        results = get_average(student)
        results.append()

#3

here:

        results = get_average(student)
        results.append()

you could do it in one line of code, but is perfectly fine two do it in two lines of code as well. But then it is important that you don't store the result of get_average(student) in results, since this will overwrite your list

you can store the result of get_average(student) in a different variable and append this to the results list, that is of course perfectly fine. Or do the append of get_average(student) to results in one line of code


#4

oh okey thank you I corrected it as one line and it said "way to go" but I only get a score "B" not any score like 91 or something like that (I saw in the other posts it is like B, 91). Is it okey?


#5

you didn't add any function calls yet, so the function is not yet executing, you will do that in the next exercise

you call get_letter_grade on line 45, that is why the output shows B


#6

okey thank you very much :slight_smile:


#7