diff --git a/driver.py b/driver.py new file mode 100644 index 0000000..2063399 --- /dev/null +++ b/driver.py @@ -0,0 +1,12 @@ +# First test to run mathgenerator +# 19 Oct 2020 + +from mathgenerator import mathgen + +problem, solution = mathgen.addition() +print(problem) +print(solution) + +problem, solution = mathgen.binarytohex() +print(problem) +print(solution) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 44218e6..1736318 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -920,6 +920,16 @@ def volumeSphereFunc(maxRadius = 100): ans=(4*math.pi/3)*r*r*r solution = f"{ans} m^3" return problem,solution + +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 + # || Class Instances # Format is: @@ -986,3 +996,4 @@ sumOfAnglesOfPolygon = Generator("Sum of Angles of Polygon", 58, "Sum of angles dataSummary = Generator("Mean,Standard Deviation,Variance", 59, "a,b,c", "Mean:a+b+c/3,Std,Var", dataSummaryFunc) 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) +binaryToHex = Generator("Binary to Hexidecimal", 61, "Hexidecimal of a=", "b", BinaryToHexFunc)