My code is right, but its saying its wrong... >_<


#1




The error message I'm receiving says: 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'd anticipate that it would exit code 0, and find no errors. Especially due to the fact that I went back an exercise, and tried the exact same code, and it gave me a B average for the class, and exited code 0.

I've looked at other Q/A's for this question, and have basically the same code. Can't see why it's not working, except for the theory that the codecademy answer key is being run using an if/else that requires the user's input to be identical to the key, else it kickbacks an error.

Ive printed the individual students, and had no issue in their dictionaries. And I've not changed my functions since the last exercise. Any hep would be nice. TIA


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]
}

students = [lloyd, alice, tyler]

# Add your function below!
def average(numbers):
    total = float(sum(numbers))/len(numbers)
    return total
    
def get_average(student):
    homework = average(student["homework"])*.1
    quizzes = average(student["quizzes"])*.3
    tests = average(student["tests"])*.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:
        get_average(student)
        results.append(get_average(students))
    return average(results)
    
print get_class_average(students)
print get_letter_grade(get_class_average(students))


#2

This is your problem. students should be student, because inside the for loop, you want to append the average of each student to results.

You also don't need this line: get_average(student)
It's not doing anything besides calling the function, but you're not setting it equal to a variable or printing it, so the computer is doing it, but it's not doing anything for you.


#3

are you referring to students should equal student in the same loop containing the "get_average(student)"?

And I was asking myself if the "get_average(student)" was wetting the code, but I wanted to be sure that I had called the function, as the exercise requested. But I see how the line "results.append(get_average(students))" calls and appends simultaneously. Either way, if the "get_average(student)" is redundant, the worst its doing i wetting up the code a little, but not crashing the program.

You're saying that its students should equal student that is the issue?


#4

Sorry I wasn't more clear, i meant that the line

results.append(get_average(students))

should be

results.append(get_average(student))
# student is a different variable than students.

Do you see the difference? students is a list where student is each item in that list.

You're right, it won't make a big difference, I just wanted to let you know that it's not really doing anything.


#5

Nevermind, I found what you meant. Typo in the function, so it wasnt reading it properly. In the future, I'll be sure to measure twice before I cut it, lol.Thanks a bunch.


#6

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