diff --git a/makeReadme.py b/makeReadme.py index 7dee39d..75448f4 100644 --- a/makeReadme.py +++ b/makeReadme.py @@ -1,9 +1,11 @@ from mathgenerator.mathgen import * write_list = [] -subjects = ['algebra', 'basic_math', 'calculus', 'computer_science', 'geometry', 'misc', 'statistics'] +subjects = ['algebra', 'basic_math', 'calculus', + 'computer_science', 'geometry', 'misc', 'statistics'] wList = getGenList() + def array2markdown_table(string): string = string.replace("[[", "
| ") string = string.replace("[", " |
| ") @@ -14,6 +16,7 @@ def array2markdown_table(string): string = string.replace("\n", "") return string + def write_table_of_contents(): lines = [] @@ -47,6 +50,7 @@ def write_table_of_contents(): with open('README.md', "w") as g: g.writelines(lines) + def gen_to_row_string(item): myGen = item[2] # NOTE: renamed 'sol' to 'solu' to make it look nicer @@ -68,13 +72,14 @@ def gen_to_row_string(item): for kwarg in kwargs_list: kwargs += '`' + kwarg + '` ' row = [myGen.id, myGen.title, prob, solu, func_name, kwargs] - #tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str( + # tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str( # row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n" tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str( row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " | " + str(row[5]) + " |\n" print('added', item[1], '-', func_name, 'to the README.md') return tableLine + def make_table_header(name): lines = [ '## ' + name + '\n', @@ -84,6 +89,7 @@ def make_table_header(name): for line in lines: write_list.append(line) + def write_subject_table(subject_name, full_gen_list): subject_list = [] # Create list of generators in given subject @@ -119,5 +125,6 @@ def main(): print("New README.md table generated") + if __name__ == "__main__": main() diff --git a/makeinit.py b/makeinit.py index d2c835e..032e251 100644 --- a/makeinit.py +++ b/makeinit.py @@ -1,5 +1,6 @@ import os + def get_filepaths(directory): """ This function will generate the file names in a directory @@ -19,9 +20,10 @@ def get_filepaths(directory): return file_paths # Self-explanatory. + # Run the above function and store its results in a variable. full_file_paths = get_filepaths("mathgenerator/funcs/statistics") full_file_paths.sort() -#print(full_file_paths) +# print(full_file_paths) for item in full_file_paths: print("from ." + item + " import *") diff --git a/mathgenerator/funcs/algebra/intersection_of_two_lines.py b/mathgenerator/funcs/algebra/intersection_of_two_lines.py index 7ce2e0c..7fbea24 100644 --- a/mathgenerator/funcs/algebra/intersection_of_two_lines.py +++ b/mathgenerator/funcs/algebra/intersection_of_two_lines.py @@ -72,4 +72,4 @@ intersection_of_two_lines = Generator( "Intersection of Two Lines", 41, "Find the point of intersection of the two lines: y = m1*x + b1 and y = m2*x + b2", "(x, y)", intersectionOfTwoLinesFunc, - ["minM=-10","maxM=10","minB=-10","maxB=10","minDenominator=1","maxDenominator=6"]) + ["minM=-10", "maxM=10", "minB=-10", "maxB=10", "minDenominator=1", "maxDenominator=6"]) diff --git a/mathgenerator/funcs/algebra/invert_matrix.py b/mathgenerator/funcs/algebra/invert_matrix.py index b598a37..dffaa14 100644 --- a/mathgenerator/funcs/algebra/invert_matrix.py +++ b/mathgenerator/funcs/algebra/invert_matrix.py @@ -81,4 +81,4 @@ def matrixInversion(SquareMatrixDimension=3, invert_matrix = Generator("Inverse of a Matrix", 74, "Inverse of a matrix A is", "A^(-1)", matrixInversion, - ["SquareMatrixDimension=3","MaxMatrixElement=99","OnlyIntegerElementsInInvertedMatrix=False"]) + ["SquareMatrixDimension=3", "MaxMatrixElement=99", "OnlyIntegerElementsInInvertedMatrix=False"]) diff --git a/mathgenerator/funcs/algebra/multiply_complex_numbers.py b/mathgenerator/funcs/algebra/multiply_complex_numbers.py index cf7314d..9592d17 100644 --- a/mathgenerator/funcs/algebra/multiply_complex_numbers.py +++ b/mathgenerator/funcs/algebra/multiply_complex_numbers.py @@ -15,4 +15,4 @@ def multiplyComplexNumbersFunc(minRealImaginaryNum=-20, multiply_complex_numbers = Generator("Multiplication of 2 complex numbers", 65, "(x + j) (y + j) = ", "xy + xj + yj -1", multiplyComplexNumbersFunc, - ["minRealImaginaryNum=-20","maxRealImaginaryNum=20"]) + ["minRealImaginaryNum=-20", "maxRealImaginaryNum=20"]) diff --git a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py index 81a677b..5fecda2 100644 --- a/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py +++ b/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py @@ -15,8 +15,10 @@ def multiplyIntToMatrix22(maxMatrixVal=10, maxRes=100, style='raw'): d1 = d * constant if style == 'latex': - problem = "\\(" + str(constant) + "\\cdot\\begin{bmatrix}" + str(a) + "&" + str(b) + "\\\\" + str(c) + "&" + str(d) + "\\end{bmatrix}=\\)" - solution = "\\(\\begin{bmatrix}" + str(a1) + "&" + str(b1) + "\\\\" + str(c1) + "&" + str(d1) + "\\end{bmatrix}\\)" + problem = "\\(" + str(constant) + "\\cdot\\begin{bmatrix}" + str( + a) + "&" + str(b) + "\\\\" + str(c) + "&" + str(d) + "\\end{bmatrix}=\\)" + solution = "\\(\\begin{bmatrix}" + str(a1) + "&" + str(b1) + \ + "\\\\" + str(c1) + "&" + str(d1) + "\\end{bmatrix}\\)" else: problem = f"{constant} * [[{a}, {b}], [{c}, {d}]] = " solution = f"[[{a1},{b1}],[{c1},{d1}]]" diff --git a/mathgenerator/funcs/basic_math/addition.py b/mathgenerator/funcs/basic_math/addition.py index 024ea2a..51c6075 100644 --- a/mathgenerator/funcs/basic_math/addition.py +++ b/mathgenerator/funcs/basic_math/addition.py @@ -20,4 +20,4 @@ def addition_func(maxSum=99, maxAddend=50, style='raw'): addition = Generator("Addition", 0, "a+b=", "c", addition_func, - ["maxSum=99", "maxAddend=50"]) + ["maxSum=99", "maxAddend=50"]) diff --git a/mathgenerator/funcs/basic_math/complex_division.py b/mathgenerator/funcs/basic_math/complex_division.py index 9e11ad5..e08b872 100644 --- a/mathgenerator/funcs/basic_math/complex_division.py +++ b/mathgenerator/funcs/basic_math/complex_division.py @@ -17,4 +17,4 @@ def complexDivisionFunc(maxRes=99, maxDivid=99, style='raw'): complex_division = Generator("Complex Division", 13, "a/b=", "c", complexDivisionFunc, - ["maxRes=99", "maxDivid=99"]) + ["maxRes=99", "maxDivid=99"]) diff --git a/mathgenerator/funcs/basic_math/cube_root.py b/mathgenerator/funcs/basic_math/cube_root.py index 715a27f..6331184 100644 --- a/mathgenerator/funcs/basic_math/cube_root.py +++ b/mathgenerator/funcs/basic_math/cube_root.py @@ -9,7 +9,8 @@ def cubeRootFunc(minNo=1, maxNo=1000, style='raw'): problem = f"\\(\\sqrt[3]{{{b}}}=\\)" solution = "\\(" + str(round(a, 2)) + "\\)" else: - problem = "What is the cube root of " + str(b) + " up to 2 decimal places?" + problem = "What is the cube root of " + \ + str(b) + " up to 2 decimal places?" solution = str(round(a, 2)) return problem, solution diff --git a/mathgenerator/funcs/basic_math/divide_fractions.py b/mathgenerator/funcs/basic_math/divide_fractions.py index 1c070df..ca54cdc 100644 --- a/mathgenerator/funcs/basic_math/divide_fractions.py +++ b/mathgenerator/funcs/basic_math/divide_fractions.py @@ -30,11 +30,13 @@ def divideFractionsFunc(maxVal=10, style='raw'): x = f"{sol_numerator}" if style == 'latex': - problem = "\\(\\frac{" + str(a) + "}{" + str(b) + "}\\div\\frac{" + str(c) + "}{" + str(d) + "}=\\)" + problem = "\\(\\frac{" + str(a) + "}{" + str(b) + \ + "}\\div\\frac{" + str(c) + "}{" + str(d) + "}=\\)" if tmp_d == 1 or tmp_d == gcd: solution = "\\(" + str(sol_numerator) + "\\)" else: - solution = "\\(\\frac{" + str(sol_numerator) + "}{" + str(sol_denominator) + "}\\)" + solution = "\\(\\frac{" + str(sol_numerator) + \ + "}{" + str(sol_denominator) + "}\\)" else: problem = f"({a}/{b})/({c}/{d})" solution = x diff --git a/mathgenerator/funcs/basic_math/division.py b/mathgenerator/funcs/basic_math/division.py index 994c63b..365b610 100644 --- a/mathgenerator/funcs/basic_math/division.py +++ b/mathgenerator/funcs/basic_math/division.py @@ -18,4 +18,5 @@ def divisionToIntFunc(maxA=25, maxB=25, style='raw'): return problem, solution -division = Generator("Division", 3, "a/b=", "c", divisionToIntFunc, ["maxA=25", "maxB=25"]) +division = Generator("Division", 3, "a/b=", "c", + divisionToIntFunc, ["maxA=25", "maxB=25"]) diff --git a/mathgenerator/funcs/basic_math/factorial.py b/mathgenerator/funcs/basic_math/factorial.py index 075905b..77535b2 100644 --- a/mathgenerator/funcs/basic_math/factorial.py +++ b/mathgenerator/funcs/basic_math/factorial.py @@ -15,4 +15,5 @@ def factorialFunc(maxInput=6): return problem, solution -factorial = Generator("Factorial", 31, "a! = ", "b", factorialFunc, ["maxInput=6"]) +factorial = Generator("Factorial", 31, "a! = ", "b", + factorialFunc, ["maxInput=6"]) diff --git a/mathgenerator/funcs/basic_math/power_of_powers.py b/mathgenerator/funcs/basic_math/power_of_powers.py index 38bda8d..095cffb 100644 --- a/mathgenerator/funcs/basic_math/power_of_powers.py +++ b/mathgenerator/funcs/basic_math/power_of_powers.py @@ -8,7 +8,8 @@ def powerOfPowersFunc(maxBase=50, maxPower=10, style='raw'): step = power1 * power2 if style == 'latex': - problem = "Simplify \\(" + str(base) + "^{" + str(power1) + "^{" + str(power2) + "}}\\)" + problem = "Simplify \\(" + str(base) + \ + "^{" + str(power1) + "^{" + str(power2) + "}}\\)" solution = f"\\({base}^{{{step}}}\\)" else: problem = f"Simplify {base}^{power1}^{power2}=" diff --git a/mathgenerator/funcs/basic_math/square_root.py b/mathgenerator/funcs/basic_math/square_root.py index 61a927f..b17b623 100644 --- a/mathgenerator/funcs/basic_math/square_root.py +++ b/mathgenerator/funcs/basic_math/square_root.py @@ -14,4 +14,5 @@ def squareRootFunc(minNo=1, maxNo=12, style='raw'): return problem, solution -square_root = Generator("Square Root", 6, "sqrt(a)=", "b", squareRootFunc, ["minNo=1", "maxNo=12"]) +square_root = Generator("Square Root", 6, "sqrt(a)=", + "b", squareRootFunc, ["minNo=1", "maxNo=12"]) diff --git a/mathgenerator/funcs/basic_math/subtraction.py b/mathgenerator/funcs/basic_math/subtraction.py index 69e9e77..98c95e5 100644 --- a/mathgenerator/funcs/basic_math/subtraction.py +++ b/mathgenerator/funcs/basic_math/subtraction.py @@ -11,4 +11,5 @@ def subtractionFunc(maxMinuend=99, maxDiff=99): return problem, solution -subtraction = Generator("Subtraction", 1, "a-b=", "c", subtractionFunc, ["maxMinuend=99", "maxDiff=99"]) +subtraction = Generator("Subtraction", 1, "a-b=", "c", + subtractionFunc, ["maxMinuend=99", "maxDiff=99"]) diff --git a/mathgenerator/funcs/geometry/area_of_circle.py b/mathgenerator/funcs/geometry/area_of_circle.py index d74a1a4..bc868eb 100644 --- a/mathgenerator/funcs/geometry/area_of_circle.py +++ b/mathgenerator/funcs/geometry/area_of_circle.py @@ -11,4 +11,4 @@ def areaCircle(maxRadius=100): area_of_circle = Generator("Area of Circle", 112, "pi*r*r=", "area", areaCircle, - ["maxRadius=100"]) + ["maxRadius=100"]) diff --git a/mathgenerator/funcs/geometry/basic_trigonometry.py b/mathgenerator/funcs/geometry/basic_trigonometry.py index 87c62bc..fb5b0fa 100644 --- a/mathgenerator/funcs/geometry/basic_trigonometry.py +++ b/mathgenerator/funcs/geometry/basic_trigonometry.py @@ -29,4 +29,4 @@ def basicTrigonometryFunc(angles=[0, 30, 45, 60, 90], basic_trigonometry = Generator("Trigonometric Values", 57, "What is sin(X)?", "ans", basicTrigonometryFunc, - ["angles=[0, 30, 45, 60, 90]","functions=['sin', 'cos', 'tan']"]) + ["angles=[0, 30, 45, 60, 90]", "functions=['sin', 'cos', 'tan']"]) diff --git a/mathgenerator/funcs/geometry/circumference.py b/mathgenerator/funcs/geometry/circumference.py index a964b1b..800bf5b 100644 --- a/mathgenerator/funcs/geometry/circumference.py +++ b/mathgenerator/funcs/geometry/circumference.py @@ -11,4 +11,4 @@ def circumferenceCircle(maxRadius=100): circumference = Generator("Circumference", 104, "2*pi*r=", "circumference", circumferenceCircle, - ["maxRadius=100"]) + ["maxRadius=100"]) diff --git a/mathgenerator/funcs/misc/arithmetic_progression_sum.py b/mathgenerator/funcs/misc/arithmetic_progression_sum.py index 82595d2..6905e91 100644 --- a/mathgenerator/funcs/misc/arithmetic_progression_sum.py +++ b/mathgenerator/funcs/misc/arithmetic_progression_sum.py @@ -8,7 +8,8 @@ def arithmeticProgressionSumFunc(maxd=100, maxa=100, maxn=100): a3 = a1 + 2 * d n = random.randint(4, maxn) apString = str(a1) + ', ' + str(a2) + ', ' + str(a3) + ' ... ' - problem = 'Find the sum of first ' + str(n) + ' terms of the AP series: ' + apString + problem = 'Find the sum of first ' + \ + str(n) + ' terms of the AP series: ' + apString an = a1 + (n - 1) * d solution = n * (a1 + an) / 2 return problem, solution diff --git a/mathgenerator/funcs/misc/set_operation.py b/mathgenerator/funcs/misc/set_operation.py index a1d5715..d3c9e9c 100644 --- a/mathgenerator/funcs/misc/set_operation.py +++ b/mathgenerator/funcs/misc/set_operation.py @@ -13,7 +13,8 @@ def set_operation(minval=3, maxval=7, n_a=4, n_b=5): 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" + 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( diff --git a/mathgenerator/funcs/statistics/conditional_probability.py b/mathgenerator/funcs/statistics/conditional_probability.py index afdfd79..42870f5 100644 --- a/mathgenerator/funcs/statistics/conditional_probability.py +++ b/mathgenerator/funcs/statistics/conditional_probability.py @@ -9,7 +9,8 @@ def conditionalProbFunc(): def BayesFormula(P_disease, true_positive, true_negative): P_notDisease = 100. - P_disease false_positive = 100. - true_negative - P_plus = (P_disease) * (true_positive) + (P_notDisease) * (false_positive) + P_plus = (P_disease) * (true_positive) + \ + (P_notDisease) * (false_positive) P_disease_plus = ((true_positive) * (100 * P_disease)) / P_plus return P_disease_plus @@ -18,7 +19,8 @@ def conditionalProbFunc(): "Test sensitivity (true positive) is equal to SN= {1:.2f}% whereas test specificity (true negative) SP= {2:.2f}%. " \ "What is the probability that this guy really has that disease?".format( P_disease, true_positive, true_negative) - answer = str(round(BayesFormula(P_disease, true_positive, true_negative), 2)) + "%" + answer = str( + round(BayesFormula(P_disease, true_positive, true_negative), 2)) + "%" return problem, answer |