If we need to run the same algorithms or formula for computations again and again, then instead of writing the same stuffs in our script file many times, we can simply write a function. This makes our script look simpler and faster to run.
Examples:
Calculating mean and standard deviation
Calculating distance from origin
Calculates distance (in km) between two coordinate points on the Earth’s surface