C3_W2_Lab_2_Dice_Simulations_Incorrect code?

In this code why is initial probability being computed as 1/(n_sides + 1) ?
Should it not be 1/(n_sides) ?

Normally this is done if the denominator is 0 and you have a division by 0! Its probably the case here as well.

I think that is not the case here.

(kindly check if I’m correct)
I tried out some example numbers.
If 1/(n_sides + 1) is used then the next line works out fine and loaded face gets twice probability.
Otherwise if 1/n_sides is given it won’t get twice probability.

Seems like correct logic but inadequate amount of explanation (hence confusion).

If the dice were equal probability, they’d use 1/n_sides, probably with a check first that n_sides isn’t zero. A zero-sided die isn’t physically possible, but defensive programming says you should validate the inputs anyway.

With 1/n_sides, it’s guaranteed that the sum of the probabilities will be 1.

So using 1/(n_sides+1) is only done because they know they’re going to increase the probability for one of the sides, but still have the sum be 1.

1 Like