Question: Q 3 : Throw Dice - 3 0 pts Consider that you are throwing a pair of dice. A single die yields values between 1

Q3: Throw Dice -30 pts
Consider that you are throwing a pair of dice. A single die yields values between 1 and 6
(inclusive), so a pair of dice yields a total between 2 and 12. However, the probabilities of the
total being 2,3,...,12 are not equal. You will have a total of 12 with probability 1/36(only
possibility is 6+6=12), but you will have a total of 7 with probability 6/36 since there are multiple
outcomes that cause a total of 7(dice outcomes: 1-6,2-5,3-4,4-3,5-2,6-1).
Open ThrowDice.py that is given to you. Here, you will see that we gave you the function to
throw a *single* die: throw_single_die. Do not modify this function. Use this function when
throwing a pair of dice. Solve the following parts.
Part A (10 pts): Implement the function record_dice_throws(throws).
The input parameter throws denotes how many times the pair of dice is thrown.
Your function should return a dictionary in which the keys of the dictionary are tuples
(first_die, second_die) and the values are the number of times the corresponding dice
outcome is observed.
For example, when throws=10000, the return value may look like this:
This means the outcome (1,1) was observed 260 times, the outcome (1,2) was observed
255 times, ..., and the outcome (6,6) was observed 256 times.
Part B (10 pts): Implement the function calculate_frequencies(throws_dict) such that:
The input parameter throws_dict is the dictionary created in Part A.
The function returns a list of tuples, each tuple consists of two elements:
The first element is the total of two dice
The second element is the ratio of cases in which that total was observed
Continuing from the above example, the return value of this function looks like this:
This means the total=2 was observed in 2.6% of the dice throws, total=3 was observed in
5.35% of the dice throws, ..., total=7 was observed in 16.82% of the dice throws, ..., and
total=12 was observed in 2.56% of the dice throws.
Since the minimum total is 2(because 1+1=2) and the maximum total is 12(because 6+6=12),
there are guaranteed to be 11 tuples in the returned list.
Hint: Sum of the normalized frequencies in this list should add up to 1. You can use this fact
to check the correctness of your results.
Part C (10 pts): Implement the function write_dict_to_file(throws_dict) to write the above
created dictionary to a file.
The input parameter throws_dict is the dictionary created in Part A.
Your function should create and write the above dictionary to a file called
diceresults.txt in the following format:
The contents of diceresults.txt is a 6x6 matrix corresponding to the counts of:
(1,1),(1,2),...,(1,6) in the first row separated by commas
(2,1),(2,2),...,(2,6) in the second row separated by commas
...
(6,1),(6,2),...,(6,6) in the sixth row separated by commas

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!