import randomsample_size = int(input("Enter the number of times you want me to roll the die: "))if (sample_size <=0):print("Please enter a positive number!")else:counter1 = 0counter2 = 0final = 0while (counter1<= sample_size):dice_value = random.randint(1,6)if ((dice_value) == 6):counter1 += 1else:counter2 +=1final = (counter2)/(sample_size) # fixing indention print("Estimation of the expected number of rolls before pigging out: " + str(final))
Is the logic used here correct? It will repeat rolling a die till a one is rolled, while keeping track of the number of rolls it took before a one showed up. It gives a value of 0.85 when I run it for high values(500+)
Thanks