import random N = 10 NUM_ROLLS = 1000000 UPPER_BOUND = 9 * N / 2 LOWER_BOUND = 3 * N / 2 counter = 0 for _ in range(NUM_ROLLS): s = sum([random.randint(1, 6) for _ in range(N)]) if s < UPPER_BOUND and s > LOWER_BOUND: counter += 1 prob = 1.0 * counter / NUM_ROLLS print(prob)