CSCI 107 Assignment 6
- Due Date: Wednesday, November 2nd 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-Assignment6.py
to the BrightSpace Assignment 6 Dropbox.
- Submission Instructions (working with one classmate): Upload your
solution, entitled
YourFirstName-YourLastName-PartnerFirstName-PartnerLastName-Assignment6.py
to the BrightSpace Assignment 6 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.
Dice Rolling Simulation
The purpose of this assignment is to help you gain experience using
while loops, for loops, functions and if
statements when solving problems.
For this assignment, you will write a program to estimate the
probability of winning a dice rolling game by simulating the game.
The user is queried for (1) the number of times the simulation should run,
(2) the value of the winning sum, (3) the number of dice that will
be rolled each time, and (4) how many sides each of these dice has. You
may assume that if a die has n sides,
that the sides are numbered 1 through
n and that rolling each number is equally likely. You
may also assume that the user will enter a valid positive integer for each of
the four requested inputs.
During one simulation, if the running total (that always starts at 0)
matches the winning sum, the game is won. If the running total exceeds
the winning sum, the game
is lost. Otherwise, the dice are rolled again and the sum of the new roll
is added to the running total.
Example (trials: 2, winning sum: 10, number of dice: 2, sides per die: 6)
Trial 1
- First roll: 2 and 6
- Second roll: 1 and 1
- Game Won!
Trial 2
- First roll: 5 and 6
- Game Lost!
Sample Output Transcript
This transcript shows three
runs of the program.
Requirements and Grading
Download and rename assignment6.py
according to the instructions above. Do not modify the provided main
function.
- 10 points - A function named all_trials exists (2 points)
with the appropriate parameters (2 points). The function should
call one_trial appropriately (6 points).
- 10 points - A function named one_trial exists (2 points)
with appropriate parameters (2 points). The function should
call roll_dice appropriately (3 points). The function
should conduct one trial and return True if the winning sum was
attained and False otherwise. (3 points).
- 10 points - A function named roll_dice exists (2 points)
with appropriate parameters (2 points). The function should call
roll_die appropriately (3 points). The function should
roll the specified number of dice with the specified sides per dice
and return the sum of that dice roll. (3 points).
For example, if 2 6-sided dice
are specified, the function might return 7.
- 10 points - A function named roll_die exists (2 points)
with appropriate parameters (2 points). The function should
roll one die with the specified number of sides once and return
the result. (6 points). For example, if a 10-sided die is specified, the
function might return 9.
- 45 points - The simulation will be tested three times with legal
values that will be different than those in the sample transcript.
Estimating the probability correctly of reaching the winning sum
for each trial is worth 15 points. (All or nothing per trial.)
- 5 points - The output format of the transcript is matched exactly.
(All or nothing.)
- 10 points - The Python solution is commented correctly,
easy to understand and does not contain unnecessary code
(2 points per type of improvement possible). Remember to provide
a comment for each function.
Test Data
- Test 1: all_trials(1000, 15, 3, 1), answer is 100.00%
- Test 2: all_trials(1000, 14, 3, 1), answer is 0.00%
- Test 3: all_trials(77777, 77, 7, 7), answer likely in range 3.30% - 3.40%