added binomial distribution function

This commit is contained in:
Vhizux
2020-10-23 21:38:54 +02:00
parent 5ffa50b1f3
commit 0c342dc37f
4 changed files with 51 additions and 1 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}

View File

@@ -111,3 +111,4 @@ from .decimal_to_bcd import *
from .circumference import * from .circumference import *
from .combine_like_terms import * from .combine_like_terms import *
from .conditional_probability import * from .conditional_probability import *
from .binomial_distribution import *

View File

@@ -0,0 +1,42 @@
from .__init__ import *
def factorial(n):
if n == 1 or n == 0:
return 1
else:
return n*factorial(n-1)
def newton_symbol(n, k):
return factorial(n)/(factorial(k)*factorial(n-k))
def binomialDistFunc():
rejected_fraction = float(random.randint(30, 40)) + random.random()
batch = random.randint(10, 20)
rejections = random.randint(1, 9)
answer = 0
rejected_fraction = round(rejected_fraction, 2)
problem = "A manufacturer of metal pistons finds that, on average, {0:}% "\
"of the pistons they manufacture are rejected because " \
"they are incorrectly sized. What is the probability that a "\
"batch of {1:} pistons will contain no more than {2:} " \
"rejected pistons?".format(rejected_fraction, batch, rejections)
for i in range(0, rejections+1):
answer += newton_symbol(batch, i)*((rejected_fraction/100.)**i) * \
((1 - (rejected_fraction/100.))**(batch-i))
answer = round(100*answer, 2)
return problem, answer
binomial_distribution = Generator("Binomial distribution", 107,
"P(X<x)=", "c", binomialDistFunc)

View File

@@ -10,4 +10,6 @@ from mathgenerator import mathgen
# print(item[2]) # print(item[2])
# print(mathgen.getGenList()) # print(mathgen.getGenList())
print(mathgen.circumference()) # print(mathgen.circumference())
print(mathgen.binomialDistFunc())