From b89c9c3178fbb5e3ebadd00c7298a626031a3f63 Mon Sep 17 00:00:00 2001 From: NarayanAdithya Date: Mon, 19 Oct 2020 22:12:24 +0530 Subject: [PATCH] Added Set operatiosn fucntion, corrected compound interest --- mathgenerator/funcs/compoundInterestFunc.py | 2 +- mathgenerator/funcs/set_operation.py | 18 ++++++++++++++++++ mathgenerator/mathgen.py | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 mathgenerator/funcs/set_operation.py diff --git a/mathgenerator/funcs/compoundInterestFunc.py b/mathgenerator/funcs/compoundInterestFunc.py index dec3e54..6f4fba3 100644 --- a/mathgenerator/funcs/compoundInterestFunc.py +++ b/mathgenerator/funcs/compoundInterestFunc.py @@ -1,6 +1,6 @@ from .__init__ import * -def compoundInterestFunc(maxPrinciple = 10000, maxRate = 10, maxTime = 10, maxPeriod = ): +def compoundInterestFunc(maxPrinciple = 10000, maxRate = 10, maxTime = 10, maxPeriod = 10): p = random.randint(100, maxPrinciple) r = random.randint(1, maxRate) t = random.randint(1, maxTime) diff --git a/mathgenerator/funcs/set_operation.py b/mathgenerator/funcs/set_operation.py new file mode 100644 index 0000000..6842efd --- /dev/null +++ b/mathgenerator/funcs/set_operation.py @@ -0,0 +1,18 @@ +from .__init__ import * + + +def set_operation(minval=3,maxval=7,n_a=4,n_b=5): + number_variables_a=random.randint(minval,maxval) + number_variables_b=random.randint(minval,maxval) + a=[] + b=[] + for i in range(number_variables_a): + a.append(random.randint(1,10)) + for i in range(number_variables_b): + b.append(random.randint(1,10)) + + a=set(a) + b=set(b) + problem= "Given the two sets a=" + str(a) + " ,b=" + str(b) + ".Find the Union,intersection,a-b,b-a and symmetric difference" + solution="Union is " + str(a.union(b)) + ",Intersection is " + str(a.intersection(b)) + ", a-b is "+str(a.difference(b)) + ",b-a is " + str(b.difference(a))+ ", Symmetric difference is "+ str(a.symmetric_difference(b)) + return problem,solution diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9f570cc..57069d8 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -114,3 +114,4 @@ meanMedian=Generator("Mean and Median", 76,"Mean and median of given set of numb intMatrix22determinant = Generator("Determinant to 2x2 Matrix", 77, "Det([[a,b],[c,d]]) =", " a * d - b * c", determinantToMatrix22) compoundInterest = Generator("Compound Interest", 78, "Compound interest for a principle amount of p dollars, r% rate of interest and for a time period of t years with n times compounded annually is = ", "A dollars", compoundInterestFunc) decimalToHexadeci = Generator("Decimal to Hexadecimal", 79,"Binary of a=", "b", deciToHexaFunc) +setoperations = Generator("Union,Intersection,Difference of Two Sets", 80, "Union,intersection,difference", "aUb,a^b,a-b,b-a,", set_operation) \ No newline at end of file