mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
* 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
23 lines
540 B
Python
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"])
|