Skip to content
Advertisement

How do I distribute a value between numbers in a list

I am creating a bias dice rolling simulator I want the user to:

1.Input the number they would like to change the prob of

2.Input the prob (in decimal form)

Then I would like my program to distribute the remainder between the other values, this is my first post – let me know if any other info is needed

My Code:

choice = int(input('Which number would you like to change to the probability of?:  '))

prob = int(input('Probability: '))

probs = [0,0,0,0,0,0]

probs[choice] = prob

Advertisement

Answer

Here is one way to do so:

choice = 2
prob = 20

choices = []
for i in range(6):
    if i == choice:
        choices.append(prob)
    else:
        choices.append((100 - prob) / 5)
print(choices)

output:

[16.0, 16.0, 20, 16.0, 16.0, 16.0]

To compute the probability, we divide the remainder (100 - prob) by the number of faces to share the remainder with (5).

We loop for each side of the die. If it is the face to be modified, we set it to prob, otherwise we set it to one-fifth of the remainder.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement