[CSC 125] Help with Second programming assignment
Andrew J. Pounds
pounds_aj at mercer.edu
Fri Jul 12 06:21:30 EDT 2013
On 07/11/13 19:49, wrote:
> For the dice assignment I am confused as to what I am trying to modify it to do. It says consistent results and I don't know if that means every time I run it I have to get 7 as the most frequent number or to get a 7 just once? I guess I'm also confused as to what to modify.
>
> Thanks
>
Hopefully this helps you out.
*Part 1: *
The first thing you need to do is make sure the program you download
from BlackBoard runs on your computer. It should run with no problem
and produce output that looks something like.
Roll Number of Occurrences
------- ---------------------
1 0
2 0
3 0
4 1
5 3
6 0
7 1
8 1
9 1
10 1
11 1
12 1
The number that was rolled most frequently was 5
When you run the program the "number that was rolled most frequently"
may be different. Probability tells us that the number should be seven,
but because we are only rolling the dice in this program 10 times, we
are not using a sample set that is big enough statistically for the
rules of probability to be applicable. To verify that, try and run the
program ten times and see if you get the same number every time. Most
likely you will not.
Now, edit the program. Look on line 12, you should see the statement
max_rolls = 10
Let's change that to
max_rolls = 100
and rerun the program ten times. Did you get the same number every
time? If not increase the value of max_rolls to 1000 and try again.
What I want to know is what number do you have to set max_rolls so that
you get the same number rolled most frequently every time.
*Part 2:*
In the part of the assignment where you create the threedice.py program
you have to make four MODIFICATIONS to the code you downloaded so that
it now rolls three six-sided dice.
From the top of the code coming down here are some of the things you
have to do:
/Change #1:/
At the appropriate place ADD a line
faces_on_dice_three = 6
/Change #2/
MODIFY the line
roll = [0] * ( ( faces_on_dice_one + faces_on_dice_two ) + 1 )
to
roll = [0] * ( ( faces_on_dice_one + faces_on_dice_two +
faces_on_dice_three ) + 1 )
/Change #3/
In the "for i" loop, change it from
dice1 = random.randrange(1,faces_on_dice_one+1,1)
dice2 = random.randrange(1,faces_on_dice_two+1,1)
roll[dice1+dice2] = roll[dice1+dice2] + 1
to
dice1 = random.randrange(1,faces_on_dice_one+1,1)
dice2 = random.randrange(1,faces_on_dice_two+1,1)
dice3 = random.randrange(1,faces_on_dice_three+1,1)
roll[dice1+dice2+dice3] = roll[dice1+dice2+dice3] + 1
/Change #4/
In the last for loop change it from
for i in range(1,faces_on_dice_one+faces_on_dice_two+1):
to
for i in range(1,faces_on_dice_one+faces_on_dice_two+faces_on_dice_three+1):
Once you have made all the changes, make sure the program runs and then
answer the same question you had to answer in Part 1 -- i.e. "To what
value must I set max_rolls so that I get the same result every time."
*Part 3:*
In part three you are doing to basically do the exact same thing you did
in part two, but now your program needs to have five dice -- each with a
different number of sides. You start this by now changing and adding
lines to the first part of the program.
Change:
faces_on_dice_one = 6
faces_on_dice_two = 6
faces_on_dice_three = 6
to
faces_on_dice_one = 4
faces_on_dice_two = 6
faces_on_dice_three = 8
faces_on_dice_four = 12
faces_on_dice_five = 20
Then perform the last three changes you did in Part 2 to now make the
program handle five dice and not just three. Once your program is
running, answer the same question "To what value must I set max_rolls so
that I get the same result every time."
As always, let me know what questions you have.
--
Andrew J. Pounds, Ph.D. (pounds_aj at mercer.edu)
Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
http://faculty.mercer.edu/pounds_aj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc125/attachments/20130712/08d0f162/attachment.html>
More information about the csc125
mailing list