Question

you will simulate rolling ?n dies and recording their sum. For example, if n=2 and the...

you will simulate rolling ?n dies and recording their sum. For example, if n=2 and the first die shows up as a 3, and the second die shows up as a 1, the sum (and the value we record) would be 4.

TO DO: Complete the two function stubs below and then demonstrate by providing code which would print out the probability distribution for rolling 2 dice 100,000 times.

seed(0)
  
def roll_and_add_dice(num_dice, num_trials = 10**6):
pass # Your code here

show_distribution(roll_and_add_dice(2),title='Probability Distribution for Sum of Two Dice')

Homework Answers

Answer #1

PYTHON CODE:

import matplotlib.pyplot as plt
import random
def roll_and_add_dice(num_dice, num_trials = 10**6):
    dict={}
    for i in range(num_dice,6*num_dice+1):
        dict[i]=0
    for i in range(0,num_trials):
        sum=0
        for j in range(0,num_dice):
            sum+=random.randint(1,6)
        dict[sum]+=1
    return dict
def show_distribution(vectors,title):
    x=list(vectors.keys())
    y=list(vectors.values())
    plt.plot(x,y)
    plt.title(title)
    plt.show()
show_distribution(roll_and_add_dice(2),title='Probability Distribution for Sum of Two Dice')

Output plot:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
• Compute the sampling distribution when you add the outcome of rolling two dice. o What...
• Compute the sampling distribution when you add the outcome of rolling two dice. o What is the probability that the sum will be higher than or equal to 9? o What is the probability that the sum will be between 4 and 6? o What is the probability that the sum will be higher than 9 given that one die is a 6? • A friend of yours rolls two dice and claims that the addition of those two...
Dice Rolling) Write an application to simulate the rolling of two dice. The application should use...
Dice Rolling) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the...
Conducting a Simulation For example, say we want to simulate the probability of getting “heads” exactly...
Conducting a Simulation For example, say we want to simulate the probability of getting “heads” exactly 4 times in 10 flips of a fair coin. One way to generate a flip of the coin is to create a vector in R with all of the possible outcomes and then randomly select one of those outcomes. The sample function takes a vector of elements (in this case heads or tails) and chooses a random sample of size elements. coin <- c("heads","tails")...
Assignment 2 1. Assume that you have two biased coins and one fair coin. One of...
Assignment 2 1. Assume that you have two biased coins and one fair coin. One of the biased coins are two tailed and the second biased one comes tails 25 percent of the time. A coin is selected randomly and flipped. What is the probability that the flipped coin will come up tail? 2. One white ball, one black ball, and two yellow balls are placed in a bucket. Two balls are drawn simultaneously from the bucket. You are given...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT