Part of the Whole--Anyone help


I got this error and no clue what was it
"Oops, try again. get_class_average([alice]) resulted in an error: 'float' object has no attribute 'append'."

My earlier code was

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

and I changed it to "results.append(get_average(student))" and is working fine.
what is the difference. can anyone help?


you declare a list:

results = []

to which you can append the average result of each student. Which is good, but then here:

results = get_average(student)

you re-assign results, now it is a float (decimal number) and then you try to append to a float. That doesn't work, .append() is a method for appending to lists, it doesn't work for floats.

You could do your approach:

x = get_average(student)

just don't overwrite the list with a float


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