Question

In: Computer Science

PYTHON CODING: “Roll” 2 dice 10,000 times keeping track of all the sums of each set...

PYTHON CODING:

“Roll” 2 dice 10,000 times keeping track of all the sums of each set of rolls in a list. Then use your program to generate a histogram summarizing the rolls of two dice 10,000 times.

Solutions

Expert Solution

from __future__ import division
import random

# to get a random number 
def dice_roll():
    return random.randint(1, 6)

# this function calculates the total number of ooccurences of all the possible outcome
def simulate(number_of_times):
    counter = {n : 0 for n in range(2, 13)}

    for i in range(number_of_times):
        first_dice = dice_roll()
        second_dice = dice_roll()
        total = first_dice + second_dice

        counter[total] += 1

    return counter

#total number of rolls
rolls = 10000
counter = simulate(rolls)  
total = sum(counter.values())
li=[]

# printing the count and probablity of occurence of all possible values
print("The count and probablity of occurence of values: \n")
for total, count in counter.items():
    print("{} - {} {:0.4f}%".format(total, count, count / rolls))
    val = round(count / rolls , 4)
    li.append(val)


import matplotlib.pyplot as plt 

import numpy as np 

# all possible outcomes
sample = [2,3,4,5,6,7,8,9,10,11,12]

# printing the plot showing probablities of all possible outcomes
x_axis = list(set(sample))
plt.bar(x_axis, li)

plt.ylabel('Probability');

PLEASE LIKE THE SOLUTION :))

IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT


Related Solutions

Our experiment is to roll 2 dice 900 times. The random variable, X, is the number...
Our experiment is to roll 2 dice 900 times. The random variable, X, is the number of times that the two dice add up to either 7 or 11. Find E(X), Var(X), and E(X^2). Assuming that the Central Limit Theorem applies, AND that the standard deviation is exactly 12.5, AND not bothering with the half-unit correction, find: P(X>225) P(X<175)
Fair Dice We roll a fair dice 10 times and register how many times we obtained...
Fair Dice We roll a fair dice 10 times and register how many times we obtained 5. (a) Find the probability to obtain 5 seven times. (b) Estimate the number of fives that will come out with the probability 0.35. (c) What is the probability of geting 30 fives when rolling a fair dice 45 times? (d) How many fives will come out with a probability of 0.25, when rollong a fair dice 45 times?
Do the following code by using python: ( Thank!) You roll two six-sided dice, each with...
Do the following code by using python: ( Thank!) You roll two six-sided dice, each with faces containing one, two, three, four, five and six spots, respectively. When the dice come to rest, the sum of the spots on the two upward faces is calculated. • If the sum is 7 or 11 on the first roll, you win. • If the sum is 2, 3 or 12 on the first roll (called “Mygame”), you lose (i.e., the “house” wins)....
Central Tendency and Variation Activity 1. Roll 4 dice 40 times, recording the sum for each...
Central Tendency and Variation Activity 1. Roll 4 dice 40 times, recording the sum for each roll.   Do it again so you have two groups of 40 numbers 2. Calculate the mean, median, mode, and midrange for both sets of data. The four numbers should be close to one another for each data set. Write a sentence or two accounting for any discrepancies. 3. Calculate a 5 number summary for both sets of data (it may help to create a...
Two four-sided dice are tossed and summed 50 times. The resulting frequencies of the sums are...
Two four-sided dice are tossed and summed 50 times. The resulting frequencies of the sums are given below: Value 2 3 4 5 6 7 8 Frequency 2 7 12 14 7 3 4 Compute the chi-squared statistic assuming both dice are fair.
We will simulate a dice game in which 2 dice are thrown. If the roll is...
We will simulate a dice game in which 2 dice are thrown. If the roll is 7 or 11, you win. If the roll is 2, 3, or 12, you lose If the roll is any other value, it establishes a point. If with a point established, that point is rolled again before a 7, you win. If, with a point established, a 7 is rolled before the point is rolled again you lose. Build your algorithm incrementally. First write...
Please using python to do the following code: You roll two six-sided dice, each with faces...
Please using python to do the following code: You roll two six-sided dice, each with faces containing one, two, three, four, five and six spots, respectively. When the dice come to rest, the sum of the spots on the two upward faces is calculated. • If the sum is 7 or 11 on the first roll, you win. • If the sum is 2, 3 or 12 on the first roll (called “Mygame”), you lose (i.e., the “house” wins). •...
Roll two dice 48 times and record the sum of the spots on the top faces...
Roll two dice 48 times and record the sum of the spots on the top faces as you roll. Then construct a probability distribution for your 48 sums. Using the probability distribution, you constructed, find the mean number of spots. (If you don't have two dice, then cut out 6 pieces of paper with each being the same size and with #1,2,3,4,5,6 written on them. Place the pieces of paper in a hat or bowl. Pull out a number, then...
(5 pts) You are going to roll a pair of dice 108 times and record the...
(5 pts) You are going to roll a pair of dice 108 times and record the sum of each roll. Before beginning, make a prediction about how you think the sums will be distributed. (Each sum will occur equally often, there will be more 12s than any other sum, there will be more 5s than any other sum, etc.) Record your prediction here: (5 pts) Roll the dice 108 times and record the sum of each roll in the table...
We roll the dice 20 times. The results we obtained are presented in the table. obtained...
We roll the dice 20 times. The results we obtained are presented in the table. obtained number 1 2 3 4 5 6 number of throws 1 1 7 4 4 3 a) The value of the relevant test statistics is: b) Assuming the significance level of 0.05, it can be considered that the dice used to roll IS / IS NOT FAIR
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT