Find the value of pi using the Monte Carlo method in Python.
The diagram above shows a circle of unit diameter inscribed within a square. This can be used to calculate the value of pi using the Monte Carlo method.
Ask the user for the number of random points to generate. In a for loop, repeat steps 3-7:
3. Generate random coordinates where the values of x and y are in the range [0, 1].
4. Calculate the distance of this point from (0.5, 0.5).
5. If that distance is less than or equal to 0.5, the random point lies within the circle.
6. If that distance is greater than 0.5, the random point lies outside the circle.
7. Keep count of the number of points inside the circle (A) and the number of points outside the circle (B).
We know that the area of the square is 1.0, and the area of the circle is pi/4. So the value of pi is approximately (A + B) / (total number of points) * 4.
Print out the value of pi.
Write a Python program to do this and show the results graphically. A hint - you will need to input a lot of points to calculate pi to even a couple of decimal places. Don't expect to input 10 or even 100 for the number of points and get a meaningful result.