The “main” part of this program is the for loop
at the bottom, which calls spinWheel , and
then report . The
spinWheel function uses
random.randrange ; the
report function uses the
odd function. This generates and reports on a
dozen spins of the wheel.
For most of our exercises, this free-floating main script is
acceptable. When we cover modules, in Part IV, “Components, Modules and Packages”,
we'll need to change our approach slightly to something like the
following.
def main():
for i in range(12):
n= spinWheel()
report( n )
main()
This makes the main operation of the script clear by
packaging it as a function. Then the only free-floating statement
in the script is the call to main .
|