In: Computer Science
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
# 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