+1(978)310-4246 credencewriters@gmail.com


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 first roll, you win.
• If you roll 2, 3 or 12 on the first roll you lose. That’s called craps.
• If you roll 4, 5, 6, 8, 9 or 10 on the first 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.
import random
# random . randrange (start , stop[, step ])
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 infinite 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

error: Content is protected !!