Probability Function for Sum on dice faces

This commit is contained in:
Ritu Raj
2020-10-17 11:47:30 +05:30
committed by GitHub
parent a4fdc4ce99
commit dedbb7027e

View File

@@ -714,6 +714,27 @@ def fourthAngleOfQuadriFunc(maxAngle = 180):
solution = angle4 solution = angle4
return problem, solution return problem, solution
def DiceSumProbFunc(maxDice=3):
a = random.randint(1,maxDice)
b = random.randint(a,6*a)
count=0
for i in [1,2,3,4,5,6]:
if a==1:
if i==b:
count=count+1
elif a==2:
for j in [1,2,3,4,5,6]:
if i+j==b:
count=count+1
elif a==3:
for j in [1,2,3,4,5,6]:
for k in [1,2,3,4,5,6]:
if i+j+k==b:
count=count+1
problem = "If {} dices rolled at the same time, Probability of getting a sum of {} =".format(a,b)
solution="{}/{}".format(count, 6**a)
return problem, solution
# || Class Instances # || Class Instances
#Format is: #Format is:
@@ -769,3 +790,4 @@ matrixMultiplication = Generator("Multiplication of two matrices", 46, "Multipl
CubeRoot = Generator("Cube Root",47,"Cuberoot of a upto 2 decimal places is","b",cubeRootFunc) CubeRoot = Generator("Cube Root",47,"Cuberoot of a upto 2 decimal places is","b",cubeRootFunc)
powerRuleIntegration = Generator("Power Rule Integration", 48, "nx^m=", "(n/m)x^(m+1)", powerRuleIntegrationFunc) powerRuleIntegration = Generator("Power Rule Integration", 48, "nx^m=", "(n/m)x^(m+1)", powerRuleIntegrationFunc)
fourthAngleOfQuadrilateral = Generator("Fourth Angle of Quadrilateral",49,"Fourth angle of Quadrilateral with angles a,b,c =","angle4",fourthAngleOfQuadriFunc) fourthAngleOfQuadrilateral = Generator("Fourth Angle of Quadrilateral",49,"Fourth angle of Quadrilateral with angles a,b,c =","angle4",fourthAngleOfQuadriFunc)
DiceSumProbability=Generator("Probability of a certain sum appearing on faces of dice",50,"If n dices are rolled then probabilty of getting sum of x is", DiceSumProbFunc)