restructure base

This commit is contained in:
lukew3
2020-10-18 23:48:13 -04:00
parent 5d4293e4da
commit 0e63b4ee11
11 changed files with 142 additions and 1 deletions

View File

@@ -53,6 +53,7 @@ from .cubeRootFunc import *
from .powerRuleIntegrationFunc import * from .powerRuleIntegrationFunc import *
from .fourthAngleOfQuadriFunc import * from .fourthAngleOfQuadriFunc import *
from .quadraticEquation import * from .quadraticEquation import *
from .hcfFunc import *
from .DiceSumProbFunc import * from .DiceSumProbFunc import *
from .exponentiationFunc import * from .exponentiationFunc import *
from .confidenceIntervalFunc import * from .confidenceIntervalFunc import *
@@ -63,3 +64,10 @@ from .sumOfAnglesOfPolygonFunc import *
from .dataSummaryFunc import * from .dataSummaryFunc import *
from .surfaceAreaSphere import * from .surfaceAreaSphere import *
from .volumeSphereFunc import * from .volumeSphereFunc import *
from .nthFibonacciNumberFunc import *
from .profitLossPercentFunc import *
from .binaryToHexFunc import *
from .multiplyComplexNumbersFunc import *
from .geomProgrFunc import *
from .geometricMeanFunc import *
from .harmonicMeanFunc import *

View File

@@ -0,0 +1,11 @@
from .__init__ import *
def binaryToHexFunc(max_dig=10):
problem = ''
for i in range(random.randint(1, max_dig)):
temp = str(random.randint(0, 1))
problem += temp
solution = hex(int(problem, 2))
return problem, solution

View File

@@ -0,0 +1,15 @@
from .__init__ import *
def geomProgrFunc(number_values=6, min_value=2, max_value=12, n_term=7, sum_term=5):
r=random.randint(min_value,max_value)
a=random.randint(min_value,max_value)
n_term=random.randint(number_values,number_values+5)
sum_term=random.randint(number_values,number_values+5)
GP=[]
for i in range(number_values):
GP.append(a*(r**i))
problem="For the given GP "+str(GP)+" ,Find the value of a,common ratio,"+str(n_term)+"th term value, sum upto "+str(sum_term)+"th term"
value_nth_term=a*(r**(n_term-1))
sum_till_nth_term=a*((r**sum_term-1)/(r-1))
solution="The value of a is {}, common ratio is {} , {}th term is {} , sum upto {}th term is {}".format(a,r,n_term,value_nth_term,sum_term,sum_till_nth_term)
return problem,solution

View File

@@ -0,0 +1,27 @@
from .__init__ import *
def geometricMeanFunc(maxValue=100, maxNum=4):
a=random.randint(1,maxValue)
b=random.randint(1,maxValue)
c=random.randint(1,maxValue)
d=random.randint(1,maxValue)
num=random.randint(2,4)
if num==2:
product=a*b
elif num==3:
product=a*b*c
elif num==4:
product=a*b*c*d
ans=product**(1/num)
if num==2:
problem=f"Geometric mean of {num} numbers {a} and {b} = "
solution = f"({a}*{b})^(1/{num}) = {ans}"
elif num==3:
problem=f"Geometric mean of {num} numbers {a} , {b} and {c} = "
solution = f"({a}*{b}*{c})^(1/{num}) = {ans}"
elif num==4:
problem=f"Geometric mean of {num} numbers {a} , {b} , {c} , {d} = "
solution = f"({a}*{b}*{c}*{d})^(1/{num}) = {ans}"
return problem,solution

View File

@@ -0,0 +1,28 @@
from .__init__ import *
def harmonicMeanFunc(maxValue=100, maxNum=4):
a=random.randint(1,maxValue)
b=random.randint(1,maxValue)
c=random.randint(1,maxValue)
d=random.randint(1,maxValue)
num=random.randint(2,4)
if num==2:
sum=(1/a)+(1/b)
elif num==3:
sum=(1/a)+(1/b)+(1/c)
elif num==4:
sum=(1/a)+(1/b)+(1/c)+(1/d)
ans=num/sum
if num==2:
problem=f"Harmonic mean of {num} numbers {a} and {b} = "
solution = f" {num}/((1/{a}) + (1/{b})) = {ans}"
elif num==3:
problem=f"Harmonic mean of {num} numbers {a} , {b} and {c} = "
solution = f" {num}/((1/{a}) + (1/{b}) + (1/{c})) = {ans}"
elif num==4:
problem=f"Harmonic mean of {num} numbers {a} , {b} , {c} , {d} = "
solution = f" {num}/((1/{a}) + (1/{b}) + (1/{c}) + (1/{d})) = {ans}"
return problem,solution

View File

@@ -0,0 +1,11 @@
from .__init__ import *
def hcfFunc(maxVal=20):
a = random.randint(1, maxVal)
b = random.randint(1, maxVal)
x, y = a, b
while(y):
x, y = y, x % y
problem = f"HCF of {a} and {b} = "
solution = str(x)
return problem, solution

View File

@@ -0,0 +1,9 @@
from .__init__ import *
def multiplyComplexNumbersFunc(minRealImaginaryNum = -20, maxRealImaginaryNum = 20):
num1 = complex(random.randint(minRealImaginaryNum, maxRealImaginaryNum), random.randint(minRealImaginaryNum, maxRealImaginaryNum))
num2 = complex(random.randint(minRealImaginaryNum, maxRealImaginaryNum), random.randint(minRealImaginaryNum, maxRealImaginaryNum))
problem = f"{num1} * {num2} = "
solution = num1 * num2
return problem, solution

View File

@@ -0,0 +1,10 @@
from .__init__ import *
def nthFibonacciNumberFunc(maxN = 100):
golden_ratio = (1 + math.sqrt(5))/2
n = random.randint(1,maxN)
problem = f"What is the {n}th Fibonacci number?"
ans = round((math.pow(golden_ratio,n) - math.pow(-golden_ratio,-n))/(math.sqrt(5)))
solution = f"{ans}"
return problem, solution

View File

@@ -0,0 +1,14 @@
from .__init__ import *
def profitLossPercentFunc(maxCP = 1000, maxSP = 1000):
cP = random.randint(1, maxCP)
sP = random.randint(1, maxSP)
diff = abs(sP-cP)
if (sP-cP >= 0):
profitOrLoss = "Profit"
else:
profitOrLoss = "Loss"
percent = diff/cP * 100
problem = f"{profitOrLoss} percent when CP = {cP} and SP = {sP} is: "
solution = percent

View File

@@ -150,3 +150,10 @@ surfaceAreaSphereGen = Generator(
"Surface Area of Sphere", 59, "Surface area of sphere with radius = a units is", "d units^2", surfaceAreaSphere) "Surface Area of Sphere", 59, "Surface area of sphere with radius = a units is", "d units^2", surfaceAreaSphere)
volumeSphere = Generator("Volume of Sphere", 60, volumeSphere = Generator("Volume of Sphere", 60,
"Volume of sphere with radius r m = ", "(4*pi/3)*r*r*r", volumeSphereFunc) "Volume of sphere with radius r m = ", "(4*pi/3)*r*r*r", volumeSphereFunc)
nthFibonacciNumberGen = Generator("nth Fibonacci number", 61, "What is the nth Fibonacci number", "Fn", nthFibonacciNumberFunc)
profitLossPercent = Generator("Profit or Loss Percent", 62, "Profit/ Loss percent when CP = cp and SP = sp is: ", "percent", profitLossPercentFunc)
binaryToHex = Generator("Binary to Hexidecimal", 63, "Hexidecimal of a=", "b", binaryToHexFunc)
complexNumMultiply = Generator("Multiplication of 2 complex numbers", 64, "(x + j) (y + j) = ", "xy + xj + yj -1", multiplyComplexNumbersFunc)
geometricprogression=Generator("Geometric Progression", 65, "Initial value,Common Ratio,nth Term,Sum till nth term =", "a,r,ar^n-1,sum(ar^n-1", geomProgrFunc)
geometricMean=Generator("Geometric Mean of N Numbers",66,"Geometric mean of n numbers A1 , A2 , ... , An = ","(A1*A2*...An)^(1/n) = ans",geometricMeanFunc)
harmonicMean=Generator("Harmonic Mean of N Numbers",67,"Harmonic mean of n numbers A1 , A2 , ... , An = "," n/((1/A1) + (1/A2) + ... + (1/An)) = ans",harmonicMeanFunc)

1
test.py Normal file
View File

@@ -0,0 +1 @@
from mathgenerator import mathgen