Question: Here's the Python code for the assignment: import sys import stdio import random import stdarray This program returns dice throws for the sum of

Here's the Python code for the assignment: import sys import stdio importHere's the Python code for the assignment:

import sys import stdio import random import stdarray

""" This program returns dice throws for the sum of two dice by computing their exact probability distribution. """

probabilities = stdarray.create1D(13, 0.0)

for i in range(1, 7): for j in range(1, 7): probabilities[i + j] += 1.0

for k in range(2, 13): probabilities[k] /= 36.0 # Run n dice throws; n = i

for i in range(2, 13): stdio.write("The probability the sum of dice throws is " + str(i) + ": ") stdio.writeln(probabilities[i])

stdio.writeln(num(probabilities))

Here's the output for the Python program:

random import stdarray """ This program returns dice throws for the sum

1. Is the program correct according to the assignment?

2. There appears to be an issue on line 23. What can I do to resolve this?

3. "How large does n have to be before your empirical results match the exact results to three decimal places?"

I appreciate your help!

Dice simulation. The following code computes the exact probability distribution for the sum of two dice: probabilities = stdarray.create1D(13, 0.0) for i in range(1,7): for j in range(1,7): probabilities[i+j] += 1.0 for k in range (2,13): probabilities[k] /= 36.0 After this code completes, probabilities[k] is the probability that the dice sum to k. Run experiments to validate this calculation simulating n dice throws, keeping track of the frequencies of occurrence of each value when you compute the sum of two random integers between 1 and 6. How large does n have to be before your empirical results match the exact results to three decimal places. Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users cinm> python dice.py The probability the sum of dice throws is 2: 0.027777777 777776 The probability the sum of dice throws is 3: 0.055555! 55555555 The probability the sum of dice throws is 4: 0.08333333333333333 The probability the sum of dice throws is 5: 0.1111111111111111 The probability the sum of dice throws is 6: 0.1388888888888889 The probability the sum of dice throws is 7: 0.16666666666666666 The probability the sum of dice throws is 8: 0.1388888888888889 The probability the sum of dice throws is 9: 0.1111111111111111 The probability the sum of dice throws is 10: 0.08333333333333333 The probability the sum of dice throws is 11: 0.05555555555555555 The probability the sum of dice throws is 12: 0.027777777 7777777776 Traceback (most recent call last): File "C:\Users cinm\dice.py", line 23, in stdio.writeln(num(probabilities)) NameError: name 'num' is not defined PS C:\Users cinm>

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!