diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 73849f0..b0cc39e 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -82,3 +82,4 @@ from .meanMedianFunc import* from .determinantToMatrix22 import * from .compoundInterestFunc import * from .deciToHexaFunc import * +from .percentageFunc import * diff --git a/mathgenerator/funcs/percentageFunc.py b/mathgenerator/funcs/percentageFunc.py new file mode 100644 index 0000000..19a4203 --- /dev/null +++ b/mathgenerator/funcs/percentageFunc.py @@ -0,0 +1,10 @@ +from .__init__ import * + +def percentageFunc(maxValue = 99, maxpercentage=99): + a = random.randint(1, maxpercentage) + b = random.randint(1, maxValue) + problem = f"What is {a}% of {b}?" + percentage = a/100*b + formatted_float = "{:.2f}".format(percentage) + solution = f"Required percentage = {formatted_float}%" + return problem, solution diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 997b8e2..ae84143 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -115,3 +115,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) +percentage = Generator("Percentage of a number",80,"What is a% of b?","percentage",percentageFunc)