Why is it considered 'powerful' to pass a function as a parameter?
Question: I am reading through _A Concise Introduction to Programming in Python_ by Mark
J.Johnson and I stumbled upon a piece of code that uses darts to estimate the
area under the graph. The code is working perfectly fine but I am getting
confused as to why you would pass a function as a parameter if you could just
call the function anyway.

    
    
    from random import uniform
    from math import exp
    
    def area(function , a ,b ,m ,n = 1000 ):   #changed parameter for better understanding
        hits = 0
        total_area = m * (b-a)
        for i in range(n):
            x = uniform(a,b)
            y = uniform(0,m)
            if y <= function(x):
               hits += 1
    
        frac = hits / float(n)
        return frac * total_area
    
    def f(x):
        return exp(-x**2)
    
    def g(x):          #new function
        return exp(-x**2) + 2
    
    def main():
        print area(f,0,2,1)
        print area(g,0,2,1)
    main()  
    

He states that passing a function as a parameter is 'powerful' but I can't see
why?


Answer: `f` is but _one graph function_. It is not the only function that you could
define to create a graph.

You can also define other functions:

    
    
    def g(x):
        return 2 * x ** 2 + x + 5
    

and pass this into `area()` **without having to alter that function**.
`area()` is generic enough to calculate the area of different graph functions,
and all you need to do is pass in the graph function to have it calculate that
area.

Had you hardcoded `f` instead of using a parameter, you could no longer do
that.

