Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading