George Alderman
George Alderman

Reputation: 35

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

Upvotes: 0

Views: 418

Answers (2)

Yeuters
Yeuters

Reputation: 1

filler_list = []
while sum(filler_list) < variable_to_distribute:
    for filler_index in range(list_length):
        if len(filler_list) < list_length:
            if sum(filler_list) < variable_to_distribute:
                filler_list.append(1)
            else:
                filler_list.append(0)
        elif sum(filler_list) < variable_to_distribute:
            filler_list[filler_index] += 1
if sum(filler_list) != variable_to_distribute:
    raise ErrorC(f"The remainder {variable_to_distribute} wasn't distributed correctly")

Upvotes: -2

Cubix48
Cubix48

Reputation: 2681

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.

Upvotes: 2

Related Questions