“91974˙CH02˙ﬁnal” — 2012/12/14 — 13:58 — page 64 — #20
64 CHAPTER 2
These will represent the position that each dart lands on our square. We can think of the
board as having a horizontal and a vertical axis, both labeled between 0 and 1. If we let
the ﬁrst number represent the horizontal distance and the second represent the vertical
distance, then the two numbers give us an exact location for the point.
Now recall that the location of the random point is important in that we need to know
whether it occurs inside or outside the quarter-circle. Our plan is to keep track of the
number of points that land inside that circle and then use that number to compute our
estimate for π. In order to do this, we need to be able to decide whether the point is in the
circle. This will require a few new ideas.
2.6.1 Boolean Expressions
To solve the problem of deciding whether a point is inside or outside of the circle, we need to
be able to ask a question. In computer science, questions are often referred to as Boolean
expressions because the result of asking them is one of the Boolean data values True or
False. These Boolean values are another primitive type in Python.
The easiest type of Boolean expression to write compares the results of two expressions.
To make this comparison, the common relational operators from mathematics such as
equal to, less than, and greater than are used. Table 2.1 shows the operators and their
meaning in Python.
Comparisons between two data values using a relational operator are called relational
expressions. Like other expressions in Python, a result is produced when relational ex-
pressions are evaluated. In this case, the result will be a Boolean value. Session 2.9 shows a
few simple examples of relational expressions. Note that the variable apple is assigned the
value 25 and is then used in an equality comparison. It is important to distinguish between