Question

In: Computer Science

Python program that simulates the rolling a die until the number 5 is first obtained. Repeat...

Python program that simulates the rolling a die until the number 5 is first obtained. Repeat the experiment 10,000 times and print out the “Average Number of Rolls to Obtain a Six on a Die”, along with the average value. Include the average number of rolls your program calculates as a comment

Please use comments to better explain what is happening

Solutions

Expert Solution

# PLEASE LIKE THE SOLUTION
# FEEL FREE TO DISCUSS IN COMMENT section
# PYTHON PROGRAM

import random
# main function
def main():
   # doing the simulation 10000 times
   times = 0

   # overall sum
   OverallSum = 0.0

   # overall count
   OverallCount = 0

   while(times < 10000):
       # now rolling dice until six comes as given in problem statement
       #Average Number of Rolls to Obtain a Six on a Die
       #temporory sum to find average for first time
       tempSum = 0.0
  
       #count
       count = 0
       while(True):
           # generate random
           dice = random.randint(1,6)
           OverallSum += dice

           count += 1
           # if sixbreak
           if(dice == 6):
               OverallCount += count
               break

       # increase times
       times += 1

   #now print average number and value  
   print("Average number of Rolls = "+str((OverallCount/10000)));
   print("Average value = "+str((OverallSum/OverallCount)));
          

          

#PROGRAM EXECUTION STARTS HERE
main()

#SAMPLE OUTPUT


Related Solutions

Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the...
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the total on the dice comes up to be a given number. Ask the user for the number that you are rolling for. To have your program roll two dice, use the rand() function this way: die1 = rand() % 6 + 1; die2 = rand() % 6 + 1; Your program then computes and prints the number of rolls it takes to get the...
PYTHON BEGINNER Problem Write a program which, given a number, simulates rolling a pair of six-sided...
PYTHON BEGINNER Problem Write a program which, given a number, simulates rolling a pair of six-sided dice that number of times. The program should keep track of how many times each possible sum comes up using a list. The list's first element should contain how many times a total of 2 was rolled, the second should contain how many times a total of 3 was rolled, and so on all the way through to 12. When all rolls are complete,...
Alice, Bob, and Charlie are rolling a fair die in that order. They keep rolling until...
Alice, Bob, and Charlie are rolling a fair die in that order. They keep rolling until one of them rolls a 6. What is the probability that each of them wins?
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] The following table shows the 36 possible combinations of the two dice. Your program should...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask the user if they want to roll again. If they don't want to roll again, the program should end. If they do want to roll again, the new number should display. At a minimum, the die should have 6 sides, but if you want to use a d12 or d20, that is fine too. USE PYTHON
A die has been "loaded" so that the probability of rolling any even number is 5...
A die has been "loaded" so that the probability of rolling any even number is 5 27 and the probability of rolling any odd number is 4 27 . (Assume the die is six-sided with each side numbered one through six.) (a) Find the following probabilities. Enter your probabilities as fractions. Pr(2 ∩ even) = Pr(even) = Pr(2 | even) = What is the probability of rolling a 2, given that an even number is rolled? (b) Find the following...
) Let X be the minimum of the two numbers obtained by rolling a die twice...
) Let X be the minimum of the two numbers obtained by rolling a die twice and Y the maximum. a) Compute E(X). b) Compute Var(X). c) Compute E(Y).
Write a complete C++ program to display the results of rolling an 8-sided die 5 times.
Write a complete C++ program to display the results of rolling an 8-sided die 5 times.
What is the expected number of rolls of a 10-sided die until 5 different numbers are...
What is the expected number of rolls of a 10-sided die until 5 different numbers are achieved?
Write a Python Program Continue to ask the user to enter a POSITIVE number until they...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they type DONE to quit. The program should DOUBLE each of the digits in the number and display the original entry AND the SUM of the doubled digits. Hint: Use the // and % operators to accomplish this. Print the COUNT of entries that were invalid Examples: if the user enters 93218, the sum of the doubled digits is 18+6+4+2+16 = 46. User Entry Output...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT