8. Part of the Whole


#1

Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected

I haven't found any error, but i always get the message above when i submit the 'code' below. Any help would be grateful

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 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(student):
    results = []
    for student in students:
        get_average(student)
        results.append(get_average(student))
    return average(results)

#2

for student in students:
get_average(student)
results.append(get_average(student))
return average(results)

remove get_average() cause your calling it twice


#3

i gave it a try to your suggestion and deleted "get_average" but outcome was same. then i tried something different and deleted 'students = [lloyd , alice , tyler]' line. after that i changed 'for student in students' to 'for student in student' and it worked. i don't exactly know why but it worked on me.


#4

Yes it must work because the function get_class_average takes an argument student in your code.
So it gets list student, but not students.


#6

Next time you post code try to do three back ticks(located above the tab key). On top of and under the code. Then you won't make #Add your function below! bold. This works because of MarkDown Syntax (I learned that from a couple of kind people on Codecademy). I can tell you didn't use it or at least didn't do it correctly. As for your code, try posting it with backticks and post the link to the exercise some people might like that. I am sort of a, but your code seems correct.


#7
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 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))

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

Thanks for the info about backsticks. This is my entire code. I am glad if i can help someone on this topic


#8

yes i saw it now, i didnt look carefully before.


#9

@olivaw
You don't seem to be using the back ticks correctly, I said to put it on the line above your code and the line under, also you should only do three, try that. Bye code, I mean all of it. For your code still doesn't look right. It should look like this:

code here

but yours looks like:
code here


#10

ahh man, ok ok i type apostrophe to do it :grin: , but i got it now. thx