Particular to General Design

When following the Particular to General strategy, we'll design several individual functions and look for common features:

  1. Write one version of the function. We'll start with the Craps game because it seems simplest:
      >>> import random
      >>> def die():
      ...    return random.randint(1,6)
      >>> def craps():
      ...    return (die(), die())

We defined a handy helper function, die(), which encapsulates a basic fact about what are sometimes called standard dice. There are five platonic solids that can be pressed into service, yielding four-sided, six-sided, eight-sided, twelve-sided, and twenty-sided dice. The six-sided die has a long history, starting as Astragali bones, which were easily trimmed into a six-sided cube.

Here's ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.