Why is my returned average value incorrect?

Question

Why is my returned average value incorrect?

Answer

A common mistake is writing out a step like numerator / denominator on a line by its own and then trying to return total. This is close, but it won’t store that result anywhere unless you tell it to!
Better yet, we can write that all on the same line as the return and save ourselves from having to create another variable, like this: return numerator / denominator.
Remember that performing math like that on a line of its own simply does the math and moves on without storing it anywhere unless you assign it to some variable.

When defining the average function, why is it necessary to convert the total variable to a float? Wouldn’t it already be a float because it’s the sum of floats?

6 Likes

I have the same doubt