Question

In: Computer Science

Write the program to analyze whether a die is fair by counting how often the values...

Write the program to analyze whether a die is fair by counting how often the values 1, 2, ..., 6 appear. • The input is a sequence of die toss values. • The output is a table with the frequencies of each die value, as shown in the following figure. o

Solutions

Expert Solution

Here iam providind the code and explanation in comments for the given problem.In this program we generated 10 random numbers as input sequence of die toss values.

Code:-

Code in text format:-

import random # library for random number generation
b = [] # declaration of an array
i = 0
one = two = three = four = five = six =0 #declaration of variablers
while (i < 10): # taking 10 random number
    b.append(random.randint(1,6)) # random in the range of 1 to 6
    #print(b[i])
    i = i+1   
  
for i in range(10): #checking the numbers in range of 10
    if (b[i] == 1): # if the current die value is equal to 1 then we increment the one variable
        one = one+1
    elif(b[i] == 2):
        two = two +1
    elif(b[i] == 3):
        three = three +1
    elif(b[i] == 4):
        four = four +1
    elif(b[i] == 5):
        five = four +1
    else:
        six = six+1
  
print("The table with the frequencies of each die value") #printing the frequencies of die values
print("one |" + " Two |" + " Three |" + " Four |" + " Five |" + " Six |")
print (str(one)+"      "+ str(two)+"      " + str(three)+"      "+str(four)+"      "+str(five)+"      "+str(six) )

Output:-


Related Solutions

Write the program to analyze whether a die is fair by counting how often the values...
Write the program to analyze whether a die is fair by counting how often the values 1, 2, ..., 6 appear. • The input is a sequence of die toss values. • The output is a table with the frequencies of each die value, as shown in the following figure. in java
The experiment of rolling a fair six-sided die twice and looking at the values of the...
The experiment of rolling a fair six-sided die twice and looking at the values of the faces that are facing up, has the following sample space. For example, the result (1,2) implies that the face that is up from the first die shows the value 1 and the value of the face that is up from the second die is 2. sample space of tossing 2 die A pair of dice is thrown. Let X = the number of multiples...
(Expected values) Suppose you roll a fair die and your opponent flips a fair coin simultaneously....
(Expected values) Suppose you roll a fair die and your opponent flips a fair coin simultaneously. You win $4 whenever a Head appears and the number of dots on the top face of the dice is either one or six. For all other outcomes, you lose $1. (a) (2pts) How many possible outcomes are there? An outcome is the combined result of both coin-flipping and dice-rolling. (b) (3pts) What is your expected payoff? (c) (3pts) What is your opponent’s expected...
Jeff and Mark are trying to decide whether a die is fair. They roll it 100...
Jeff and Mark are trying to decide whether a die is fair. They roll it 100 times, with the results shown below: 19 ones, 13 twos, 15 threes, 21 fours, 18 fives, 14 sixes. Average ≈ 3.43, SD ≈ 1.76. Jeff wants to make a z-test, Mark wants to make a χ2 -test. Who is right? Explain briefly. Then, calculate the p-value of the respective test. Is the die fair?
1. The experiment of rolling a fair six-sided die twice and looking at the values of...
1. The experiment of rolling a fair six-sided die twice and looking at the values of the faces that are facing up, has the following sample space. For example, the result (1,2) implies that the face that is up from the first die shows the value 1 and the value of the face that is up from the second die is 2. (1,1)       (1,2)       (1,3)       (1,4)       (1,5)       (1,6) (2,1)       (2,2)       (2,3)       (2,4)       (2,5)       (2,6) (3,1)       (3,2)       (3,3)       (3,4)       (3,5)       (3,6)...
Consider the following experiment: Simultaneously toss a fair coin and, independently, roll a fair die. Write...
Consider the following experiment: Simultaneously toss a fair coin and, independently, roll a fair die. Write out the 12 outcomes that comprise the sample space for this experiment. Let X be a random variable that takes the value of 1 if the coin shows “heads” and the value of 0 if the coin shows “tails”. Let Y be a random variable that takes the value of the “up” face of the tossed die. And let Z = X + Y....
Write a C++ die roller program. We need you to write a program that will roll...
Write a C++ die roller program. We need you to write a program that will roll dice for them, but not just six-sided dice. Your program needs to be able to take an input in for form nDx or ndx where the d is the letter d or D. n may or not be present. If it is, it represents the number of dice. If not, assume it is a 1. x may or may not be present. If it...
In a Java program, how could I write a program that can assign values that would...
In a Java program, how could I write a program that can assign values that would make a rock paper scissors game work? I have a program that will generate a computer response of either rock, paper, or scissors but how can I compare a user input of "rock", "paper", or "scissors" so that we can declare either the user or the computer the winner.
Assume that you have a fair 6 sided die with values {1, 2, 3, 4, 5,...
Assume that you have a fair 6 sided die with values {1, 2, 3, 4, 5, 6} and a fair 12 sided die with values {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}. A discrete random variable is generated by rolling the two dice and adding the numerical results together. (a) Create a probability mass function that captures the probability of all possible values of this random variable. You may use R or draw the pmf...
Let X be the result of rolling a fair ten-sided die a) Write down the distribution...
Let X be the result of rolling a fair ten-sided die a) Write down the distribution of X, and compute its expected value. You must show all your work. b) How would you use R to simulate 4 rolls of ten-sided die and sum the result, then repeat this action 10,000 times, and store it in a variable called toss4. Please type the code in the space below.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT