Added function binarytoHex()

This commit is contained in:
William Welch
2020-10-18 18:28:30 -05:00
parent 4331db74d0
commit 26c43e9f16
2 changed files with 23 additions and 0 deletions

12
driver.py Normal file
View File

@@ -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)

View File

@@ -920,6 +920,16 @@ def volumeSphereFunc(maxRadius = 100):
ans=(4*math.pi/3)*r*r*r ans=(4*math.pi/3)*r*r*r
solution = f"{ans} m^3" solution = f"{ans} m^3"
return problem,solution 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 # || Class Instances
# Format is: # 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) 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) 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) 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)