How is Everybody Doing? Problem


#1



Hello again!

Back with another problem again it seems.

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

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

       
H = [lloyd, alice, tyler]       
print get_class_average(H)
print get_letter_grade(get_class_average(H))

That's my code, but it come up with the error:
Oops, try again. One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade

I've tried just copy and pasting code that other people say works (same result), straight up typing the H-list into the final two lines instead of H (doesn't change anything of course) and i've been staying at the code for the past 3 days straight. I still don't see what the problem is. Could it be indentation? or the way i ordered the commands?

Help!

And thank you for your time to read and answer this.


#2

here:

H = [lloyd, alice, tyler]

the exercise validates the present of this lists, but it also expect it to be called students, not H (you called it students when you declared it in 3. put it together)


#3

stetim94 is right.
place H = [lloyd, alice, tyler] some lines up.
Above your class def get_class_average(students):
and change H in students = [lloyd, alice, tyler]


#4

why is this important? Function parameters serve as placeholder, you need to be sure to define students before the function calls if you want to use students as argument


#5

Really? I've tried deleting the H = line and replacing the H's with students but it comes up with the exact same error.

Here it is again, with H replaced with students:

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

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

       
     
print get_class_average(students)
print get_letter_grade(get_class_average(students))

#6

i don't see the list with students?


#7

I looked into it. I added students near the beginning, and the lesson allowed me to pass.

But in theory, there was nothing wrong (mechanically) with my original code, right? The lesson just wanted me to use the students list instead of another list? Because i seem to redefine it later on in the code anyways when i'm trying to calculate i think the class average.


#8

your code was technically fine.

You created the list in 3. put it together, so the exercise knows what the list is called and can use it for validation purposes


#9

Since it says one of those names aren't right, the appropriate thing to do would be to check them all, such as by printing them. A missing variable would result in an error saying it's not defined and then you've identified which one of them is missing


#10

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