Write a program that performs a simulation to estimate the p
Solution
from random import randint #import randint to get a random number between 1 to six for the dice
 import time
#taking input from the user for number of simulaations
 def number_of_simulations():
     num = int(input(\"Please enter the number of simulations you\'d like: \"))
     #After checking it turns out that approximately 4 million simulations happen in 10 seconds on my computer. Hence accepting input less than that.
     while(num>4000000):
         print(\"Please enter a value less than 4,000,000 so that the simulation completes within 10 seconds.\")
         num = input(\"Please enter the number of simulations you\'d like: \")
     return num
#simulate a single set of 5 dice rolls.
 def roll():
     #simulating a dice roll using randint between 1 to 6
     dice_num = randint(1, 6)
     for i in range(0, 4):
         previous_dice_num = dice_num
         dice_num = randint(1, 6)
         if dice_num!=previous_dice_num:
             return False #returning false if any of the numbers is not equal
     return True
#function to simulate the entire experiment
 def simulate(n):
    #counter to keep track of favorable outcome
     fav = 0
    #iterating through the number of simulations requested by the user
     for i in range(n):
         if roll():
             fav += 1
     #return the Probability
     return fav*1.0/n
n = number_of_simulations()
 start_time = time.time()
 print(\"Probability: \", simulate(n))
 end_time = time.time()
 print(\"Time: \", end_time-start_time)

