When following the Particular to General strategy, we'll design several individual functions and look for common features:
- 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 ...