Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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:

image text in transcribed

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, 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago