PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

[FIXED] How do I distribute a value between numbers in a list

 October 07, 2022     list, math, probability, python, statistics     No comments   

Issue

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

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.



Answered By - Cubix48
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing