[Tutor] Help with return results statement.

Danny Yoo danny.yoo at gmail.com
Thu Oct 22 15:07:50 EDT 2015


An additional suggestion:

> =====
> # Add your functions below!
> def average(numbers):
>     total = sum(numbers)
>     total = total / len(numbers)
>     return total

Don't re-assign total here.  The problem is that conceptually "total" no
longer represents the total in the second assignment.  It makes the name
meaningless.

One way to resolve the problem is to just return the value.

#################
def average(numbers):
    total = sum(numbers)
    return total / len(numbers)
#################

That is, the problem isn't one of computation, but of compassion.  Help
make code readable.


More information about the Tutor mailing list