Files
mathgenerator/mathgenerator/funcs/computer_science/binary_to_decimal.py
Luke Weiler 8e264e6b23 Remove mathgen (#396)
* Improve generator __init__ function

* Move Generator to new file, remove mathgen

* Remove getGenList redundancies

* Add backwards compatibility import mathgen from

* Insort to genList

* Linter fixes

* Lint fixes
2022-12-19 14:01:52 -05:00

23 lines
540 B
Python

from ...generator import Generator
import random
def gen_func(max_dig=10, format='string'):
problem = ''
for i in range(random.randint(1, max_dig)):
temp = str(random.randint(0, 1))
problem += temp
if format == 'string':
solution = int(problem, 2)
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return problem, solution
binary_to_decimal = Generator("Binary to Decimal", 15, gen_func,
["max_dig=10"])