Broken Code error in spite of correct output


#1



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


Error:One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade.
However the output area gives the accurate output. I manually cross checked the output.


This should be a correct piece of code. I can't quite figure out the mistake. Any help would be appreciated.


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):
    homeworkt=average(student["homework"])
    quizzest=average(student["quizzes"])
    testst=average(student["tests"])
    return 0.1*homeworkt+0.3*quizzest+0.6*testst
    
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 a in students:
        k=get_average(a)
        results.append(k)
    
    return average(results)

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


#2

Hello

The instructions are -

Finally, print out the result of calling get_class_average with your students list.
Your students should be [lloyd, alice, tyler].
Then, print the result of get_letter_grade for the class's average.

Your code -

def get_class_average(students):
results=[]
for a in students:
k=get_average(a)
results.append(k)

return average(results)

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

I think that the use of 'a' and 'k' might cause the problem.
Remember the instructions have key words which must display.
Here is the first bit to help you -

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

See the differences in our codes. No broken or missing code. Everything I typed can be found above the definition for get_class_average.
You have to check the last three lines regarding the student list and two printing codes.

Hope that helps.


#3

Well, I did use your code and reduced the number of variables in the last three lines. However, the error still persists. Note that I have completely eliminated variables a and k


#4

Hey, sorry to bother you again. I found out the error in my code. Although the output was correct I was not being able to complete the exercise.
My original code(last bit):

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

My modified code:

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

Although there is absolutely no difference between the two, I was being debarred from moving on to the next lesson.


#5

Hello

Would you mind sending me the whole code with the spaces?
Want to run it in my simulator.

Thanks


#6

Hello

The following section in your code -

def get_average(student):
homeworkt=average(student["homework"])
quizzest=average(student["quizzes"])
testst=average(student["tests"])
return 0.1*homeworkt+0.3*quizzest+0.6*testst

Why are there 't' at the end of some of the words?

Just check that quick? It is the from the original post you started with.

Thanks


#7

Your error message listed a number of variables, you just had to check them one at a time.

Your reasoning should be:
Oh it says a b or c is missing, let's check whether I've got a b and c


#8

Hello

Did you get my message regarding the indentations? How is the coding going?


#9

I sent you a message containing the code. It's completely functional now.
Thanks!


#10

I know. I did that. It's just that while I had a, b and c all along, they were named differently


#11

Congrats dude. Awesomeness!


#12

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