Float object is not iterable


#1



Have been trying to figure it out for a while, now it says that "get_class_average([alice]) resulted in an error: 'float' object is not iterable". How can I solve it and what's the rationale behind it? thanks for the help


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


#2

please see that in your a variable you have a number (float type) which is an average of single student. hence, above line is wrong and is giving you this error - you should append your a and not average from your a. so:
results.append(a)
then you have to correct the last line - you should return the average of your results, correct line is:

return average(results)

I think the ''float' object is not iterable comes when you call average(a) function - program cannot run sum(numbers) out of single a. sum() requires a sequence of arguments.