From 0e63b4ee11e4ec894107d05d3974328ceaac8d08 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Sun, 18 Oct 2020 23:48:13 -0400 Subject: [PATCH] restructure base --- mathgenerator/funcs/__init__.py | 8 ++++++ mathgenerator/funcs/binaryToHexFunc.py | 11 ++++++++ mathgenerator/funcs/geomProgrFunc.py | 15 ++++++++++ mathgenerator/funcs/geometricMeanFunc.py | 27 ++++++++++++++++++ mathgenerator/funcs/harmonicMeanFunc.py | 28 +++++++++++++++++++ mathgenerator/funcs/hcfFunc.py | 11 ++++++++ .../funcs/multiplyComplexNumbersFunc.py | 9 ++++++ mathgenerator/funcs/nthFibonacciNumberFunc.py | 10 +++++++ mathgenerator/funcs/profitLossPercentFunc.py | 14 ++++++++++ mathgenerator/mathgen.py | 9 +++++- test.py | 1 + 11 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 mathgenerator/funcs/binaryToHexFunc.py create mode 100644 mathgenerator/funcs/geomProgrFunc.py create mode 100644 mathgenerator/funcs/geometricMeanFunc.py create mode 100644 mathgenerator/funcs/harmonicMeanFunc.py create mode 100644 mathgenerator/funcs/hcfFunc.py create mode 100644 mathgenerator/funcs/multiplyComplexNumbersFunc.py create mode 100644 mathgenerator/funcs/nthFibonacciNumberFunc.py create mode 100644 mathgenerator/funcs/profitLossPercentFunc.py create mode 100644 test.py diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 73bd406..efb1ce7 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -53,6 +53,7 @@ from .cubeRootFunc import * from .powerRuleIntegrationFunc import * from .fourthAngleOfQuadriFunc import * from .quadraticEquation import * +from .hcfFunc import * from .DiceSumProbFunc import * from .exponentiationFunc import * from .confidenceIntervalFunc import * @@ -63,3 +64,10 @@ from .sumOfAnglesOfPolygonFunc import * from .dataSummaryFunc import * from .surfaceAreaSphere 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 * diff --git a/mathgenerator/funcs/binaryToHexFunc.py b/mathgenerator/funcs/binaryToHexFunc.py new file mode 100644 index 0000000..0f3e962 --- /dev/null +++ b/mathgenerator/funcs/binaryToHexFunc.py @@ -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 diff --git a/mathgenerator/funcs/geomProgrFunc.py b/mathgenerator/funcs/geomProgrFunc.py new file mode 100644 index 0000000..3e3ad5c --- /dev/null +++ b/mathgenerator/funcs/geomProgrFunc.py @@ -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 diff --git a/mathgenerator/funcs/geometricMeanFunc.py b/mathgenerator/funcs/geometricMeanFunc.py new file mode 100644 index 0000000..05ded2b --- /dev/null +++ b/mathgenerator/funcs/geometricMeanFunc.py @@ -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 diff --git a/mathgenerator/funcs/harmonicMeanFunc.py b/mathgenerator/funcs/harmonicMeanFunc.py new file mode 100644 index 0000000..035273f --- /dev/null +++ b/mathgenerator/funcs/harmonicMeanFunc.py @@ -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 diff --git a/mathgenerator/funcs/hcfFunc.py b/mathgenerator/funcs/hcfFunc.py new file mode 100644 index 0000000..40be783 --- /dev/null +++ b/mathgenerator/funcs/hcfFunc.py @@ -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 diff --git a/mathgenerator/funcs/multiplyComplexNumbersFunc.py b/mathgenerator/funcs/multiplyComplexNumbersFunc.py new file mode 100644 index 0000000..f959d4d --- /dev/null +++ b/mathgenerator/funcs/multiplyComplexNumbersFunc.py @@ -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 diff --git a/mathgenerator/funcs/nthFibonacciNumberFunc.py b/mathgenerator/funcs/nthFibonacciNumberFunc.py new file mode 100644 index 0000000..023a007 --- /dev/null +++ b/mathgenerator/funcs/nthFibonacciNumberFunc.py @@ -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 diff --git a/mathgenerator/funcs/profitLossPercentFunc.py b/mathgenerator/funcs/profitLossPercentFunc.py new file mode 100644 index 0000000..533c294 --- /dev/null +++ b/mathgenerator/funcs/profitLossPercentFunc.py @@ -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 diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 14d5668..a3beac6 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -149,4 +149,11 @@ dataSummary = Generator("Mean,Standard Deviation,Variance", surfaceAreaSphereGen = Generator( "Surface Area of Sphere", 59, "Surface area of sphere with radius = a units is", "d units^2", surfaceAreaSphere) volumeSphere = Generator("Volume of Sphere", 60, - "Volume of sphere with radius r m = ", "(4*pi/3)*r*r*r", volumeSphereFunc) \ No newline at end of file + "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) diff --git a/test.py b/test.py new file mode 100644 index 0000000..288c5b3 --- /dev/null +++ b/test.py @@ -0,0 +1 @@ +from mathgenerator import mathgen