When Python evaluates
odd
(
n
), first it evaluates
n
; second, it assigns this argument value to the
local parameter of odd
(named
spin
); third, it applies odd
, the
suite of statements is executed, ending with return 1 or return 0; fourth,
this result returned to the calling statement so that it can finish it's
execution.
We would use this function like this.
s = random.randrange(37)
# 0 <= s <= 36, single-0 roulette
if s == 0:
print "zero"
elif odd(s):
print s, "odd"
else:
print s, "even"
We evaluate a function named random.randrange to create a random
number, s
. The
if
clause handles the
case where s
is zero. The first
elif
clause evaluates our odd
function. To do this
evaluation, Python must set spin
to the value of
s
and execute the suite of statements that are the body
of odd
. The suite of statements will return either
True
or False
. Since the
if
and
elif
clauses handle zero and
odd cases, all that is left is for s
to be even.