Part of the Whole (updated)


#1

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 = float(total) / len(numbers)
return total
def get_average(student):
homework = average(student['homework'])
quizzes = average(student['quizzes'])
tests = average(student['tests'])
grade = 0.1 * average(student['homework']) + 0.3 * average(student['quizzes']) + 0.6 * average(student['tests'])
return grade
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'
else:
return 'F'
print get_letter_grade(get_average(lloyd))
def get_class_average(students):
students = [lloyd,alice,tyler]
results = []
results.append(get_average(students))
return average(results)


#2

also I have my syntax fixed it just didn't show up


#3

please use markup as i recommend here:


#4

With the realisation that the posted code is different and that others therefore can't see your code, have a look at the buttons in the post editor and see if there isn't one to keep it intact. Alternatively, see it as a problem to be solved or worked around, you can for example post it on some other site and link to it.

You can call your function the same way as is mentioned in codecademy's error message to get the same exception show up in the console, this time including the location for where it crashes which you can then use to investigate what happened there (either by just reading the code in that area or by adding prints to find out what's what)


#5

It is still not showing my syntax but here we are

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 = float(total) / len(numbers)
    return total
def get_average(student):
    homework = average(student['homework'])
    quizzes = average(student['quizzes'])
    tests = average(student['tests'])
    grade = 0.1 * average(student['homework']) + 0.3 * average(student['quizzes']) + 0.6 * average(student['tests'])
    return grade
    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'
    else:
        return 'F'
print get_letter_grade(get_average(lloyd))
def get_class_average(students):
    students = [lloyd,alice,tyler]
    results = []
    results.append(get_average(students))
    return average(results)

#6

okay so now it's fixed but what am I doing wrong? I have been getting the error
Oops, try again. get_class_average([alice]) resulted in an error: list indices must be integers, not str


#7

for get_class_average, don't overwrite your function parameter, supply the list of students as argument when calling the function. An advantage of doing this means that your get_class_average also works for a list with one, two (any combi) or three student

get_average() is designed to calculate the average grade for a single student, so we will need a loop to calculate the average grade for each student, which we then can append to results list


#8

can you explain this? I'm not entirely sure what I need to do beyond what I already have


#9

also I thought I already did get_average() ?


#10

have you implemented any of the ideas i mentioned already or do you not understand it at all?


#11

No, I don't really understand it


#12

okay so in my code, I do have the list in the parenthesis when I call get_class_average


#13

Your second line in the get_class_average function is not necessary and is causing your error. Step 03 in the instructions says "For each student item in the class list.." This should be a strong indicator that you should use some type of for loop, instead of defining the the list like you did in your second line.


#14

lets break it down:

students = [lloyd,alice,tyler]
# function deceleration 
def get_class_average(students):
    print students

# function call
get_class_average(students)

so your students list, gets copied into the function parameter (students), so now we need to calculate our class average. First for each student in students we need to calculate the student average grade (using get_average()) and append this average to results

finally, we need to return the average of this list:

return average(results)

which you do correctly


#15

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