Student beocmes the teacher -- Class Average


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/4?curriculum_id=4f89dab3d788890003000096


Here is the error im getting and cannot figure out why my code is returning this
"

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

"

only thing I can think of is that one of the students values are not correct (like90 instead of 85) but they all match my original list any other thoughts?


these are the instructions:

      
        Instructions

Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students.First, make an empty list called results.For each student item in the class list, calculate get_average(student) and then call results.append() with that result.Finally, return the result of calling average() with results.


students = ["Lloyd", "Alice", "Tyler"]


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):
    return  average(student["homework"]) * .10 + \
    average(student["quizzes"]) * .30  +\
    average(student["tests"]) * .60 
    
    
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"
    
get_letter_grade(get_average(lloyd))


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


#2

Looks like you're returning before you append anything within results.

Your return results should also line up (whitespace wise) with the for, not 4 indented.
This way the results will return after your for loop executes, not on the first student.

I haven't done this specific one, but try something like this:

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

#3

This is the exact code I typed, and I still get the same error as jheadclarke.


#4

def average(numbers):
    total = sum(numbers)
    total = float(total)
    total = total/len(numbers)
    return total
    
def get_average(student):
    return  average(student["homework"]) * .10 + \
    average(student["quizzes"]) * .30  +\
    average(student["tests"]) * .60 

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

I just put this within the link to the lesson and it works fine.
I'm a bit confused as to how this is bombing for you?
What is your exact code?


#5

This list should contain only the names of the dictionaries. Logically, it would follow the dictionaries in the source listing.

students = [ lloyd, alice, tyler ]

#6

I found my mistake; my last line was indented one too many times. It needs to line up with the for loop to work. After coding in C++ for a year, I still need to get used to how crucial the whitespaces are in Python.


#7

That was my exact code above, I have tried messing around with it for the given help so far and still nothing.


#8

I am still getting this error after updating my code:
Oops, try again.
get_class_average([alice, lloyd]) returned 91.15 instead of 85.85 as expected

code is as follows:

`
students = ["lloyd", "alice", "tyler"]

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):
return average(student["homework"]) * .10 + \
average(student["quizzes"]) * .30 +\
average(student["tests"]) * .60

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"

get_letter_grade(get_average(lloyd))

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


#9

This list should rightly follow the dictionaries it refers to. The dictionary names will not be in quotes.


#10

I just updated my list and still receiving the same error :frowning:

`

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):
return average(student["homework"]) * .10 + \
average(student["quizzes"]) * .30 +\
average(student["tests"]) * .60

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"

students = [lloyd, alice, tyler]
get_letter_grade(get_average(lloyd))

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


#11

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

this is the error im receiving


#12

What happens if you change the parameter from 'students' to 'pupils' in get_class_average?


#17