32 KiB
mathgenerator
A math problem generator, created for the purpose of giving self-studying students and teaching organizations the means to easily get access to random math problems to suit their needs.
To try out generators, go to https://lukew3.github.io/mathgenerator
See CONTRIBUTING.md for information about how to contribute.
Table of Contents
Installation
The project can be install via pip
pip install mathgenerator
Basic Usage
Here is an example of how you would generate an addition problem:
from mathgenerator import mathgen
#generate an addition problem
problem, solution = mathgen.addition()
#another way to generate an addition problem using genById()
problem, solution = mathgen.genById(0)
Creating a worksheet
If you wish to create a worksheet, you can use the worksheetgen package. Install this with pip install worksheetgen. Here is an example of how a worksheet would be generated.
from mathgenerator import mathgen
from worksheetgen.wg import Worksheet
worksheet = Worksheet("Worksheet title")
worksheet.add_instruction("Instructions")
# Writes 10 problems generated with id 1, [0] at the end specifies to take problem, and not solution.
for _ in range(10):
worksheet.add_problem(mathgen.genById(1)[0])
worksheet.write_pdf()
This creates the pdf ws.pdf in your current directory
Documentation
-
getGenList()returns a list of all generators in the repository in the format[id, title, self, funcname, subjectname] -
genById(id)generates a problem, solution set with generator ididin the format[problem, solution] -
Pass the kwarg
format=latexto return problem and solution set as latex. If latex is not available for that generator, the problem will return the string "Latex unavailable" -
Pass the kwarg
format=rawto return just the raw data for each generator. An array of each variable necessary to the generator is returned.
List of Generators
algebra
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 11 | Basic Algebra | 10x + 4 = 10 | 3/5 | basic_algebra | maxVariable=10 |
||||||||||||||||
| 12 | Logarithm | log3(6561) | 8 | log | maxBase=3 maxVal=8 |
||||||||||||||||
| 17 | Integer Multiplication with 2x2 Matrix | 7 * 6, 0], [10, 0 = | 42,0],[70,0 | multiply_int_to_22_matrix | maxMatrixVal=10 maxRes=100 |
||||||||||||||||
| 20 | Midpoint of the two point | (-1,11),(-14,15)= | (-7.5,13.0) | midpoint_of_two_points | maxValue=20 |
||||||||||||||||
| 21 | Factoring Quadratic | x^2-4x-5 | (x-5)(x+1) | factoring | range_x1=10 range_x2=10 |
||||||||||||||||
| 23 | Solve a System of Equations in R^2 | -8x + 9y = -32, -2x - 3y = 34 | x = -5, y = -8 | system_of_equations | range_x=10 range_y=10 coeff_mult_range=10 |
||||||||||||||||
| 24 | Distance between 2 points | Find the distance between (-6, -4) and (13, -13) | sqrt(442) | distance_two_points | maxValXY=20 minValXY=-20 |
||||||||||||||||
| 26 | Linear Equations | 4x + 17y = -187, 20x + -9y = 99 | x = 0, y = -11 | linear_equations | n=2 varRange=20 coeffRange=20 |
||||||||||||||||
| 41 | Intersection of Two Lines | Find the point of intersection of the two lines: y = -3x + 8 and y = -5x + 7 | (-1/2, 19/2) | intersection_of_two_lines | minM=-10 maxM=10 minB=-10 maxB=10 minDenominator=1 maxDenominator=6 |
||||||||||||||||
| 43 | Cross Product of 2 Vectors | [-17, 5, -14] X [-7, 10, 12] = | [200, 302, -135] | vector_cross | minVal=-20 maxVal=20 |
||||||||||||||||
| 45 | Simple Interest | Simple interest for a principle amount of 7064 dollars, 8% rate of interest and for a time period of 4 years is = | 2260.48 | simple_interest | maxPrinciple=10000 maxRate=10 maxTime=10 |
||||||||||||||||
| 46 | Multiplication of two matrices | Multiply
|
|
matrix_multiplication | maxVal=100 max_dim=10 |
||||||||||||||||
| 50 | Quadratic Equation | Zeros of the Quadratic Equation 34x^2+110x+49=0 | [-0.53, -2.7] | quadratic_equation | maxVal=100 |
||||||||||||||||
| 65 | Multiplication of 2 complex numbers | (-13-14j) * (-18-15j) = | (24+447j) | multiply_complex_numbers | minRealImaginaryNum=-20 maxRealImaginaryNum=20 |
||||||||||||||||
| 72 | Dot Product of 2 Vectors | [11, 15, 2] . [-12, 6, 16] = | -10 | vector_dot | minVal=-20 maxVal=20 |
||||||||||||||||
| 74 | Inverse of a Matrix | Inverse of Matrix Matrix(48, 56, 11], [2, 79, 45], [81, 43, 55) is: | Matrix(2410/244197, -869/81399, 1651/244197], [3535/244197, 583/81399, -2138/244197], [-6313/244197, 824/81399, 3680/244197) | invert_matrix | SquareMatrixDimension=3 MaxMatrixElement=99 OnlyIntegerElementsInInvertedMatrix=False |
||||||||||||||||
| 77 | Determinant to 2x2 Matrix | Det(48, 42], [83, 76) = | 162 | int_matrix_22_determinant | maxMatrixVal=100 |
||||||||||||||||
| 78 | Compound Interest | Compound interest for a principle amount of 5893 dollars, 3% rate of interest and for a time period of 7 year is = | 7247.65 | compound_interest | maxPrinciple=10000 maxRate=10 maxTime=10 |
||||||||||||||||
| 100 | complex Quadratic Equation | Find the roots of given Quadratic Equation x^2 + 8x + 5 = 0 | simplified solution : ((-0.683, -7.317)), generalized solution : ((-8 + sqrt(44))/21, (-8 - sqrt(44))/21) | complex_quadratic | prob_type=0 max_range=10 |
||||||||||||||||
| 105 | Combine Like terms | 8x^2 + 5x^4 + 1x^1 + 4x^7 + 7x^1 + 2x^6 + 3x^5 + 1x^1 + 4x^5 | 9x^1 + 8x^2 + 5x^4 + 7x^5 + 2x^6 + 4x^7 | combine_like_terms | maxCoef=10 maxExp=20 maxTerms=10 |
||||||||||||||||
| 111 | Expanding Factored Binomial | (-6x+6)(-1x+2) | 6x^2-18x+12 | expanding | range_x1=10 range_x2=10 range_a=10 range_b=10 |
basic_math
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|---|---|---|---|---|---|
| 0 | Addition | 21+45= | 66 | addition | maxSum=99 maxAddend=50 |
| 1 | Subtraction | 52-9= | 43 | subtraction | maxMinuend=99 maxDiff=99 |
| 2 | Multiplication | 1*4= | 4 | multiplication | maxMulti=12 |
| 3 | Division | 144/9= | 16 | division | maxA=25 maxB=25 |
| 6 | Square Root | sqrt(81)= | 9 | square_root | minNo=1 maxNo=12 |
| 8 | Square | 10^2= | 100 | square | maxSquareNum=20 |
| 13 | Complex Division | 91/92= | 0.99 | complex_division | maxRes=99 maxDivid=99 |
| 16 | Fraction Division | (8/2)/(2/8) | 16 | divide_fractions | maxVal=10 |
| 28 | Fraction Multiplication | (2/4)*(10/3) | 5/3 | fraction_multiplication | maxVal=10 |
| 31 | Factorial | 4! = | 24 | factorial | maxInput=6 |
| 44 | Compare Fractions | Which symbol represents the comparison between 2/1 and 8/9? | > | compare_fractions | maxVal=10 |
| 47 | Cube Root | What is the cube root of 87 up to 2 decimal places? | 4.43 | cube_root | minNo=1 maxNo=1000 |
| 53 | Exponentiation | 1^1 = | 1 | exponentiation | maxBase=20 maxExpo=10 |
| 71 | Absolute difference between two numbers | -66--25 | = | 41 | |
| 80 | Percentage of a number | What is 85% of 55? | 46.75 | percentage | maxValue=99 maxpercentage=99 |
| 90 | isprime | Is 59 prime? | Yes | is_prime | max_num=100 |
| 97 | Power of Powers | Simplify 42^3^5= | 42^15 | power_of_powers | maxBase=50 maxPower=10 |
calculus
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|---|---|---|---|---|---|
| 7 | Power Rule Differentiation | 5x^3 | 15x^2 | power_rule_differentiation | maxCoef=10 maxExp=10 maxTerms=5 |
| 48 | Power Rule Integration | 1x^3 + 10x^7 + 10x^1 + 2x^7 + 6x^10 | (1/3)x^4 + (10/7)x^8 + (10/1)x^2 + (2/7)x^8 + (6/10)x^11 + c | power_rule_integration | maxCoef=10 maxExp=10 maxTerms=5 |
| 88 | Differentiation | differentiate w.r.t x : d(cos(x)+7*x^(-2))/dx | -sin(x) - 14/x^3 | differentiation | diff_lvl=2 |
| 89 | Definite Integral of Quadratic Equation | The definite integral within limits 0 to 1 of the equation 63x^2 + 1x + 68 is = | 89.5 | definite_integral | max_coeff=100 |
| 110 | Stationary Points | f(x)=5x^3 + x^2 + 5x + 1 | stationary_points | maxExp=3 maxCoef=10 |
computer_science
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|---|---|---|---|---|---|
| 4 | Binary Complement 1s | 01100001= | 10011110 | binary_complement_1s | maxDigits=10 |
| 5 | Modulo Division | 94%96= | 94 | modulo_division | maxRes=99 maxModulo=99 |
| 14 | Decimal to Binary | Binary of 65= | 1000001 | decimal_to_binary | max_dec=99 |
| 15 | Binary to Decimal | 1100 | 12 | binary_to_decimal | max_dig=10 |
| 56 | Fibonacci Series | The Fibonacci Series of the first 20 numbers is ? | [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181] | fibonacci_series | minNo=1 |
| 62 | nth Fibonacci number | What is the 85th Fibonacci number? | 259695496911123328 | nth_fibonacci_number | maxN=100 |
| 64 | Binary to Hexidecimal | 0 | 0x0 | binary_to_hex | max_dig=10 |
| 73 | Binary 2's Complement | 2's complement of 111011 = | 101 | binary_2s_complement | maxDigits=10 |
| 79 | Decimal to Hexadecimal | Binary of 398= | 0x18e | decimal_to_hexadeci | max_dec=1000 |
| 84 | Converts decimal to octal | The decimal number 3316 in Octal is: | 0o6364 | decimal_to_octal | maxDecimal=4096 |
| 91 | Binary Coded Decimal to Integer | Integer of Binary Coded Decimal 1 is = | 5768 | bcd_to_decimal | maxNumber=10000 |
| 103 | Decimal to Binary Coded Decimal | BCD of Decimal Number 8538 is = | 21510 | decimal_to_bcd | maxNumber=10000 |
geometry
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|---|---|---|---|---|---|
| 18 | Area of Triangle | Area of triangle with side lengths: 15 19 6 = | 37.416573867739416 | area_of_triangle | maxA=20 maxB=20 maxC=20 |
| 19 | Triangle exists check | Does triangle with sides 17, 30 and 50 exist? | No | valid_triangle | maxSideLength=50 |
| 22 | Third Angle of Triangle | Third angle of triangle with angles 86 and 40 = | 54 | third_angle_of_triangle | maxAngle=89 |
| 25 | Pythagorean Theorem | The hypotenuse of a right triangle given the other two lengths 7 and 13 = | 14.76 | pythagorean_theorem | maxLength=20 |
| 29 | Angle of a Regular Polygon | Find the angle of a regular polygon with 5 sides | 108.0 | angle_regular_polygon | minVal=3 maxVal=20 |
| 32 | Surface Area of Cube | Surface area of cube with side = 14m is | 1176 m^2 | surface_area_cube | maxSide=20 unit='m' |
| 33 | Surface Area of Cuboid | Surface area of cuboid with sides = 8m, 20m, 7m is | 712 m^2 | surface_area_cuboid | maxSide=20 unit='m' |
| 34 | Surface Area of Cylinder | Surface area of cylinder with height = 45m and radius = 10m is | 3455 m^2 | surface_area_cylinder | maxRadius=20 maxHeight=50 unit='m' |
| 35 | Volum of Cube | Volume of cube with side = 19m is | 6859 m^3 | volume_cube | maxSide=20 unit='m' |
| 36 | Volume of Cuboid | Volume of cuboid with sides = 6m, 18m, 6m is | 648 m^3 | volume_cuboid | maxSide=20 unit='m' |
| 37 | Volume of cylinder | Volume of cylinder with height = 6m and radius = 19m is | 6804 m^3 | volume_cylinder | maxRadius=20 maxHeight=50 unit='m' |
| 38 | Surface Area of cone | Surface area of cone with height = 23m and radius = 6m is | 561 m^2 | surface_area_cone | maxRadius=20 maxHeight=50 unit='m' |
| 39 | Volume of cone | Volume of cone with height = 28m and radius = 1m is | 29 m^3 | volume_cone | maxRadius=20 maxHeight=50 unit='m' |
| 49 | Fourth Angle of Quadrilateral | Fourth angle of quadrilateral with angles 34 , 28, 124 = | 174 | fourth_angle_of_quadrilateral | maxAngle=180 |
| 57 | Trigonometric Values | What is tan(30)? | 1/√3 | basic_trigonometry | angles=[0, 30, 45, 60, 90] functions=['sin', 'cos', 'tan'] |
| 58 | Sum of Angles of Polygon | Sum of angles of polygon with 4 sides = | 360 | sum_of_polygon_angles | maxSides=12 |
| 60 | Surface Area of Sphere | Surface area of Sphere with radius = 10m is | 1256.6370614359173 m^2 | surface_area_sphere | maxSide=20 unit='m' |
| 61 | Volume of Sphere | Volume of sphere with radius 88 m = | 2854543.2384361913 m^3 | volume_sphere | maxRadius=100 |
| 70 | Angle between 2 vectors | angle between the vectors [445.87, 643.14, 725.82, 487.36, 253.17, 866.17, 410.55, 67.88, 225.36, 525.53, 635.68, 918.19, 52.39] and [203.15, 873.75, 556.81, 879.48, 909.96, 767.26, 845.65, 785.81, 745.86, 876.93, 877.72, 619.64, 905.23] is: | 0.61 radians | angle_btw_vectors | maxEltAmt=20 |
| 75 | Area of a Sector | Given radius, 30 and angle, 283. Find the area of the sector. | Area of sector = 2222.67680 | sector_area | maxRadius=49 maxAngle=359 |
| 86 | Degrees to Radians | Angle 110 in radians is = | 1.92 | degree_to_rad | max_deg=360 |
| 87 | Radians to Degrees | Angle 3 in degrees is = | 171.89 | radian_to_deg | max_rad=3 |
| 95 | Curved surface area of a cylinder | What is the curved surface area of a cylinder of radius, 36 and height, 86? | CSA of cylinder = 19452.74 | curved_surface_area_cylinder | maxRadius=49 maxHeight=99 |
| 96 | Perimeter of Polygons | The perimeter of a 9 sided polygon with lengths of [49, 15, 63, 56, 87, 59, 13, 35, 84]cm is: | 461 | perimeter_of_polygons | maxSides=12 maxLength=120 |
| 104 | Circumference | Circumference of circle with radius 39 | 245.04422698000386 | circumference | maxRadius=100 |
| 108 | Arc length of Angle | Given radius, 24 and angle, 323. Find the arc length of the angle. | Arc length of the angle = 135.29792 | arc_length | maxRadius=49 maxAngle=359 |
| 112 | Area of Circle | Area of circle with radius 79 | 19614.571428571428 | area_of_circle | maxRadius=100 |
misc
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|---|---|---|---|---|---|
| 9 | LCM (Least Common Multiple) | LCM of 3 and 12 = | 12 | lcm | maxVal=20 |
| 10 | GCD (Greatest Common Denominator) | GCD of 12 and 6 = | 6 | gcd | maxVal=20 |
| 27 | Prime Factorisation | Find prime factors of 55 | [5, 11] | prime_factors | minVal=1 maxVal=200 |
| 40 | Common Factors | Common Factors of 42 and 55 = | [1] | common_factors | maxVal=100 |
| 51 | HCF (Highest Common Factor) | HCF of 18 and 15 = | 3 | hcf | maxVal=20 |
| 55 | Comparing surds | Fill in the blanks 94^(1/2) _ 76^(1/8) | > | surds_comparison | maxValue=100 maxRoot=10 |
| 63 | Profit or Loss Percent | Loss percent when CP = 568 and SP = 428 is: | 24.647887323943664 | profit_loss_percent | maxCP=1000 maxSP=1000 |
| 66 | Geometric Progression | For the given GP [5, 40, 320, 2560, 20480, 163840] ,Find the value of a,common ratio,6th term value, sum upto 6th term | The value of a is 5, common ratio is 8 , 6th term is 163840 , sum upto 6th term is 187245.0 | geometric_progression | number_values=6 min_value=2 max_value=12 n_term=7 sum_term=5 |
| 67 | Geometric Mean of N Numbers | Geometric mean of 3 numbers 17 , 96 and 65 = | (179665)^(1/3) = 47.33813788872301 | geometric_mean | maxValue=100 maxNum=4 |
| 68 | Harmonic Mean of N Numbers | Harmonic mean of 3 numbers 18 , 16 and 15 = | 3/((1/18) + (1/16) + (1/15)) = 16.240601503759397 | harmonic_mean | maxValue=100 maxNum=4 |
| 69 | Euclidian norm or L2 norm of a vector | Euclidian norm or L2 norm of the vector[5.635634088805297, 25.010440136540968, 396.32418220000267, 107.53011787670164, 545.6874361227574, 184.6826627723569, 174.06643859373185, 464.3440136677789, 7.224673708081664, 8.876015680626349, 492.79488489985056, 829.9627437839996, 114.95586474177044, 158.35106542211696, 957.6000447259205, 232.33194190040297, 458.35579555527363, 362.21539076262013, 811.1637217594521, 912.2055239005433] is: | 2125.927366092163 | euclidian_norm | maxEltAmt=20 |
| 81 | Celsius To Fahrenheit | Convert 68 degrees Celsius to degrees Fahrenheit = | 154.4 | celsius_to_fahrenheit | maxTemp=100 |
| 82 | AP Term Calculation | Find the term number 10 of the AP series: -71, -56, -41 ... | 64 | arithmetic_progression_term | maxd=100 maxa=100 maxn=100 |
| 83 | AP Sum Calculation | Find the sum of first 23 terms of the AP series: -37, 30, 97 ... | 16100.0 | arithmetic_progression_sum | maxd=100 maxa=100 maxn=100 |
| 85 | Converts decimal to Roman Numerals | The number 0 in Roman Numerals is: | MCDX | decimal_to_roman_numerals | maxDecimal=4000 |
| 92 | Complex To Polar Form | 14.87(-10.0theta + i11.0theta) | 2.31 | complex_to_polar | minRealImaginaryNum=-20, maxRealImaginaryNum=20 |
| 93 | Union,Intersection,Difference of Two Sets | Given the two sets a={8, 6, 7} ,b={3, 6, 7, 8, 10}.Find the Union,intersection,a-b,b-a and symmetric difference | Union is {3, 6, 7, 8, 10},Intersection is {8, 6, 7}, a-b is set(),b-a is {10, 3}, Symmetric difference is {3, 10} | set_operation | minval=3 maxval=7 n_a=4 n_b=5 |
| 94 | Base Conversion | Convert 17284 from base 12 to base 6. | 413444 | base_conversion | maxNum=60000 maxBase=16 |
| 98 | Quotient of Powers with Same Base | The Quotient of 30^9 and 30^8 = 30^(9-8) = 30^1 | 30 | quotient_of_power_same_base | maxBase=50 maxPower=10 |
| 99 | Quotient of Powers with Same Power | The Quotient of 1^6 and 18^6 = (1/18)^6 = 0.05555555555555555^6 | 2.9401194111858127e-08 | quotient_of_power_same_power | maxBase=50 maxPower=10 |
| 101 | Leap Year or Not | Year 2024 | is a leap year | is_leap_year | minNumber=1900 maxNumber=2099 |
| 102 | Minute to Hour conversion | Convert 357 minutes to Hours & Minutes | 5 hours and 57 minutes | minutes_to_hours | maxMinutes=999 |
| 106 | signum function | signum of 608 is = | 1 | signum_function | min=-999 max=999 |
| 109 | Binomial distribution | A manufacturer of metal pistons finds that, on average, 40.25% of the pistons they manufacture are rejected because they are incorrectly sized. What is the probability that a batch of 14 pistons will contain no more than 8 rejected pistons? | 93.94 | binomial_distribution | `` |
statistics
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|---|---|---|---|---|---|
| 30 | Combinations of Objects | Number of combinations from 20 objects picked 1 at a time | 20 | combinations | maxlength=20 |
| 42 | Permutations | Number of Permutations from 17 objects picked 0 at a time = | 1 | permutation | maxlength=20 |
| 52 | Probability of a certain sum appearing on faces of dice | If 3 dice are rolled at the same time, the probability of getting a sum of 8 = | 21/216 | dice_sum_probability | maxDice=3 |
| 54 | Confidence interval For sample S | The confidence interval for sample [216, 210, 293, 229, 272, 227, 262, 252, 281, 284, 258, 275, 285, 261, 283, 289, 288, 212, 282, 254, 221, 278, 271, 297, 225, 251, 222, 238, 246, 213, 215, 280, 263, 236] with 95% confidence is | (264.22307058301857, 245.7181058875697) | confidence_interval | `` |
| 59 | Mean,Standard Deviation,Variance | Find the mean,standard deviation and variance for the data[13, 8, 13, 48, 10, 27, 46, 21, 16, 46, 26, 41, 8, 27, 39] | The Mean is 25.933333333333334 , Standard Deviation is 203.12888888888887, Variance is 14.252329244333673 | data_summary | number_values=15 minval=5 maxval=50 |
| 76 | Mean and Median | Given the series of numbers [10, 22, 36, 42, 45, 62, 72, 78, 86, 93]. find the arithmatic mean and mdian of the series | Arithmetic mean of the series is 54.6 and Arithmetic median of this series is 53.5 | mean_median | maxlen=10 |
| 107 | Conditional Probability | Someone tested positive for a nasty disease which only 1.55% of population have. Test sensitivity (true positive) is equal to SN= 97.42% whereas test specificity (true negative) SP= 91.78%. What is the probability that this guy really has that disease? | 15.73% | conditional_probability | `` |