Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q 3 : Throw Dice - 3 0 pts Consider that you are throwing a pair of dice. A single die yields values between 1
Q: Throw Dice pts
Consider that you are throwing a pair of dice. A single die yields values between and
inclusive so a pair of dice yields a total between and However, the probabilities of the
total being are not equal. You will have a total of with probability only
possibility is but you will have a total of with probability since there are multiple
outcomes that cause a total of dice outcomes:
Open ThrowDice.py that is given to you. Here, you will see that we gave you the function to
throw a single die: throwsingledie. Do not modify this function. Use this function when
throwing a pair of dice. Solve the following parts.
Part A pts: Implement the function recorddicethrowsthrows
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
firstdie, seconddie and the values are the number of times the corresponding dice
outcome is observed.
For example, when throws the return value may look like this:
This means the outcome was observed times, the outcome was observed
times, and the outcome was observed times.
Part B pts: Implement the function calculatefrequenciesthrowsdict such that:
The input parameter throwsdict 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 was observed in of the dice throws, total was observed in
of the dice throws, total was observed in of the dice throws, and
total was observed in of the dice throws.
Since the minimum total is because and the maximum total is because
there are guaranteed to be tuples in the returned list.
Hint: Sum of the normalized frequencies in this list should add up to You can use this fact
to check the correctness of your results.
Part C pts: Implement the function writedicttofilethrowsdict to write the above
created dictionary to a file.
The input parameter throwsdict is the dictionary created in Part A
Your function should create and write the above dictionary to a file called
diceresultstxt in the following format:
The contents of diceresults.txt is a x matrix corresponding to the counts of:
in the first row separated by commas
in the second row separated by commas
in the sixth row separated by commas
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started