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 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:
What's the issue with my code? And does my program answer the assignment? 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, inStep 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