Programming I: Data Structures With Python
Due: April 14, 2021
Problem Set 03
April 7, 2021
Problem 1: A craps game
Craps is a popular game of chance. There are many versions of the game. One version of craps goes as
Ã¢â‚¬Â¢ You roll two six-sided dice. The sum of the spots on the two upward faces is between 2 and 12.
Ã¢â‚¬Â¢ If you roll a total of 7 or 11 on the Ã¯Â¬Ârst roll, you win.
Ã¢â‚¬Â¢ If you roll 2, 3 or 12 on the Ã¯Â¬Ârst roll you lose. ThatÃ¢â‚¬â„¢s called craps.
Ã¢â‚¬Â¢ If you roll 4, 5, 6, 8, 9 or 10 on the Ã¯Â¬Ârst roll, that is your Ã¢â‚¬Å“pointÃ¢â‚¬ÂÃ¢â‚¬â€œa target for you to repeat to win the game.
Ã¢â‚¬Â¢ You win if you repeat your Ã¢â‚¬Å“pointÃ¢â‚¬Â before you roll a 7, you win.
Ã¢â‚¬Â¢ If you roll a 7 before you repeat your Ã¢â‚¬Å“pointÃ¢â‚¬Â, you lose.
Write a function that simulates a single game of craps. It should repeat rolls of the dice until it is determined
that the player wins or loses. You may want to write a helper function that simulates the results of rolling two
To simulate rolls, you will want to use the standard Python random library. The random library has a function
called randrange that takes as arguments lower & upper limits to the random integer. Read the documentation to be sure youÃ¢â‚¬â„¢re invoking the function correctly.
# random . randrange (start , stop[, step ])
### YOUR CODE GOES HERE ####
Once youÃ¢â‚¬â„¢ve got the single game code working, write code that runs a simulation of 500,000 craps games.
This could take a while, depending on your computer. You can print out progress reports if youÃ¢â‚¬â„¢re nervous
about the code being in an inÃ¯Â¬Ânite loop. Or you could try running simulations for 1,000 games and making
sure that itÃ¢â‚¬â„¢s working. Record the number of times the player wins vs. loses, and print out the results.
Finally, comment on the results that you see. What do you think your results say about the game of craps?
Purchase answer to see full