Files
mathgenerator/mathgenerator/funcs/computer_science/decimal_to_binary.py
Luke Weiler 20d3294a93 Remove asterisk imports from subject inits (#391)
* removed asterisk imports from subject inits

* import Generator from the right init level
2022-12-19 02:06:10 -05:00

21 lines
505 B
Python

from ...__init__ import Generator
import random
def gen_func(max_dec=99, format='string'):
a = random.randint(1, max_dec)
b = bin(a).replace("0b", "")
if format == 'string':
problem = "Binary of " + str(a) + "="
solution = str(b)
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return a, str(b)
decimal_to_binary = Generator("Decimal to Binary", 14, gen_func,
["max_dec=99"])