CSCI 107 Assignment 7
- Due Date: Monday, April 10th no later than 11:59 p.m.
- Partner Information: You may complete this assignment individually or
with exactly one classmate.
- Submission Instructions (working alone): Upload your solution,
entitled YourFirstName-YourLastName-Assignment7.py
to the BrightSpace Assignment 7 Dropbox.
- Submission Instructions (working with one classmate): Upload your
solution, entitled
YourFirstName-YourLastName-PartnerFirstName-PartnerLastName-Assignment7.py
to the BrightSpace Assignment 7 Dropbox. Note: If you work with a
partner, only one person needs to submit a solution. If you both
submit a solution, the submission that will be graded is the one from
the partner whose last name comes alphabetically first.
- Deadline Reminder: Once the submission deadline passes, BrightSpace
will no longer accept your submission and you will no longer be able
to earn credit. Thus, if you are not able to fully complete the
assignment, submit whatever you have before the deadline so that
partial credit can be earned.
Craps Simulation
The purpose of this assignment is to help you gain experience using
while loops to solve problems.
For this assignment, you will simulate a simplified game of craps to estimate
the percentage of time that the game is won. To play, two six-sided
dice are rolled. If they add up to 7 or 11, the game is won. If they add
up to 2, 3 or 12, the game is lost. If they add up to any other number,
the two dice are repeatedly rolled until either a 7 is rolled (in which case
the game is lost) or the original sum is rolled (in which case the game
is won).
Example
- Roll 1: a 6 and 3. Keep rolling!
- Roll 2: a 1 and 2. Keep rolling!
- Roll 3: a 4 and 5. You win! (The game is a win since the sum of the
two dice, 9, matches the sum of the first roll.)
Sample Output Transcript
This transcript shows two runs of the program.
In the first simulation, the program simulates playing craps 100 times.
In the second simulation, the program simulates playing craps
1,000,000 times.
- Note 1: the program requires the user to enter a number between
100 and 5,000,000. If the user enters a number that is too small or
too large, the program asks the user to enter another integer.
- Note 2: the program does not need to handle the case where something
other than an integer is entered.
The Assignment - 100 points
Requirements and Grading
- 10 points - A function named simulate_one_game exists (2 points)
that has no parameters (2 points).
The function returns True (3 points) if a simulated game of
craps is won and False (3 points) if it is lost.
- 15 points - A function named get_integer exists (2 points).
Its three parameters indicate the smallest valid integer (1 point),
the largest valid integer (1 point), and a custom message (2 points).
The function prints the custom message (2 points) and then
repeatedly prompts the user for an integer in the desired
range until one is entered (5 points) and then returns it (2 points).
- 10 points - A function named main exists (1 point) that has no parameters (1 point).
This function calls the other two functions to solve the problem (8 points).
- 30 points - The simulation is correct (10 points per logic error up to 30 points.)
- 15 points - The output format of the transcript is matched exactly (3 points per
type of difference.)
- 10 points - The Python solution is easy to understand and
does not contain unnecessary code (2 points per type of improvement possible).
- 10 points - Comments are used appropriately (2 points per type of improvement possible).