File I/O and top-down design

In class exercises
Run update21 and change to the inclass/w07-design directory.
[w07-design]$ ls
File Demo
Open in vim. In a separate window, change to the w07-design directory so you can run the program using python
The basic idea is to start with the general problem and try to express a solution in terms of smaller problems. Then each smaller problem is handled in the same way until eventually the problems get so small that they are trivial to solve. Then you write each piece, test it, and join it in the with the solution so far.

Let's demonstrate this idea with the dice game Craps.

A player rolls a pair of six-sided dice.

If the initial roll is 2, 3, or 12, the player loses.

If the initial roll is 7 or 11, the player wins.

Any other initial roll causes the player to "roll for point". This means that the player keeps rolling either until she re-rolls the initial value (a win) or rolls a 7 (a loss).

Let's write a program to simulate multiple games of craps and estimate the probability that the player wins.


Input: Number of games to simulate

Output: Probability of winning