Lesson goal: Playing Craps

Previous: Rolling a die until a 6 comes up | Home | Next: Introduction: Make a flashing animation

Craps is a dice game that works like this: you roll two dice. If the sum of the two dice comes up either 7 or 11, you win. If the sum is 2, 3 or 12 you lose. If none of these, the sum becomes your "point." And you continue to roll until your point comes up again. If it does, you win. But, if a 7 comes up first, you lose. What's the probability of winning at Craps?

This is an excellent project in figuring a probability using dice and in praticing coding with loops and if-statements.

Here we define a function called roll_two() that will handling rolling two dice and returning their sum. The main body of code is just about implementing the logic of craps. Fill in the ?? groups until you get it working.

Note after the initial checks for 7/11 or 2/3/12, we enter a little "sub-game" of continuous rolls in a while-loop that keeps rolling until either "point" or 7 is rolled.

Now you try. Choose a value of N and edit the ?? groups.

Type your code here:


See your results here: