Question

the question is to simulate the result of tossing n die and generate a probability graph based on your simulation in python3

the result is supposed to be normal distribution, but mine isn't. i would like to know what's wrong in my code.

def roll_and_add_dice(num_dice, num_trials = 10**6): outcomes = [] sum_of_die = 0 for j in range(num_trials): for i in range(

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Note: Brother sometimes while uploading on HomeworkLib the indentations change. So, I request you to verify it with screenshot once. This is the link where I have saved the code to

https://onlinegdb.com/S13gIuDIB

Hi the code you provided is working absolutely fine. What I think is there is some error in hist type.

Below is my code to this problem

import random
import matplotlib.pyplot as plt
def roll_and_add_dice(num_dice,num_trials=10**4):
n=num_trials;
nd=num_dice;
out=[];
S=0;
for j in range(n):
for i in range(nd):
S=S+random.randint(1,7);
out.append(S);
S=0;
return out;
  
out=roll_and_add_dice(2);
plt.hist(out,density=True);
plt.show();

M Drafts (5) - gurkaranpreet.sing x C We Are Going To Plot The Olyr X Trinket X C Computer Science questionC x C My Q&A | Che

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
the question is to simulate the result of tossing n die and generate a probability graph...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (b) IULUI SAPT Two dice are rolled. Find the probabilities of the following events. 13. The...

    (b) IULUI SAPT Two dice are rolled. Find the probabilities of the following events. 13. The first die is 3 or the sum is 8. 14. The second die is 5 or the sum is 10. One card is drawn from an ordinary deck of 52 cards. Find the probabilities of drawing the following cards. 15. (a) A 9 or 10 (b) A red card or a 3 (c) A 9 or a black 10 (d) A heart or a...

  • part C (b) Consider the experiment on pp. 149-156 of the online notes tossing a coin...

    part C (b) Consider the experiment on pp. 149-156 of the online notes tossing a coin three times). Consider the following discrete random variable: Y = 2[number of H-3[number of T). (For example, Y (HHT) = 2.2-3.1=1, while Y (TTH) = 2.1-3.2 = -4.) Repeat the analysis found on pp. 149-156. That is, (i) find the range of values of Y: (ii) find the value of Y(s) for each s ES: (iii) find the outcomes in the events A -Y...

  • Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of...

    Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of scoring outcomes of a single turn in a game called Pig. Your Task For this assignment you will simulate a given number of hold?at?N turns of a game called Pig, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single turn of this game. The value of N will be acquired via user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT