Python code for Figure 8.15