Why do we create another variance variable after the function?


#1

Question

Why do we create another variance variable after the function?

Answer

In order to use the functions we just made, we need to give them values. We have the list, grades, to pass our other functions, but the function to calculate standard deviation expects a variance value to be provided, which we don’t have anywhere.
It may seem confusing because we do have a variable named variance inside of the grades_variance() and grades_std_deviation() functions, but those variables only exist inside of those functions. This is called scope of a variable, or where it is accessible.
Think of the stuff inside of functions as only being accessible inside of that function, which is why return is so useful.


FAQ: Learn Python - Exam Statistics - Standard Deviation