How to do it...

  1. Design all of the output display into two broad areas:
    1. Functions (or classes) that do no processing, but display result objects.
    2. Logging may be for debugging, monitoring, audit, or some other control. This is a cross-cutting concern that will be embedded in the rest of the application.

For this example, there are two outputs—the sequence of sequences, and some additional information to confirm that processing worked properly. A count of each number rolled is a handy way to establish that the simulated dice were fair.


The sequence of rolls needs to be written to a file. This suggests that the write_rolls() function is given an iterator as a parameter. Here's a function that iterates and dumps values to a file in YAML ...

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.