Min 2
Write a function called min_2(number_1, number_2)
that
returns the minimum of the two parameters, number_1
and number_2
. The function should not use the
built-in min
function.
Test Cases
print('Input:' ?, ',', ?, '\t\tActual:', min_2(?, ?), '\tExpected:', ?)
Min 3
Write a function called min_3(number_1, number_2,
number_3)
that returns the minimum of the 3 parameters to
the function, number_1
, number_2
,
number_3
. The
function should not use the built-in min
function.
Test Cases
print('Input:', ?, ',', ?, ',', ?, '\tActual:', min_3(?, ?, ?), '\tExpected:', ?)
Point in Circle
Earlier this semester we estimated π using the Leibniz approximation. Another way of estimating the value of pi is to use Monte Carlo Estimation. The technique is named after the casino because it depends on random chance and probability. A program that estimates π this way must test whether a point is inside of a circle.
Details
Create a Python program that uses the turtle to draw a large circle centered in the window. The program should generate a random points in the window and draw them as a small dot. The color of the dot should be determined by whether or not the dot is inside the large circle. If the center of a dot is inside the circle, the dot should be green, if the center of a dot is outside the circle, the dot should be red. Assume a dot exactly on the edge of the large circle is inside the circle.
Example

-
Create a function! For example,
draw_dot(x, y)
that draws a dot at the specified location and the appropriate color. By creating a function that plots a single point, it is easier to test the code without any randomness. Once the function is testied and working, call it repeatedly inside of a loop with random x,y coordinates. -
A point is inside of a circle if the distance between the point and the center of the circle is less than the radius of the circle.
-
The distance between two points can be computed using the Euclidean Distance formula:
d=√(x1−x2)2+(y1−y2)2
Where d is the distance between the points (x1,y1) and (x2,y2).
Challenge
To perform a Monte Carlo estimation of π, we need to estimate the area of the circle. Create a program that draws a large circle circumscribed by a square in the center of the window. That is, the width and height of the square is the same as the diameter of the circle. The program should generate a large number of random points. It should be possible for a random point to be located anywhere inside the square but nowhere outside of the square. The fraction of points that are inside the circle is an estimate of the area of the circle as a fraction of the area of the square. Since the area of a circle is πr2, the program can use the estimated area to solve for π