diff --git a/mathgen.py b/mathgen.py new file mode 100644 index 0000000..ffb2ebe --- /dev/null +++ b/mathgen.py @@ -0,0 +1,43 @@ +import random + + +genList = [] + + +# || Generator class +class Generator: + def __init__(self, title, id, generalProb, generalSol, func): + self.title = title + self.id = id + self.generalProb = generalProb + self.generalSol = generalSol + self.func = func + genList.append([id, title, self]) + + def __str__(self): + return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol + + def __call__(self, **kwargs): + return self.func(**kwargs) + + +def isprime(max_a=100): + a = random.randint(2, max_a) + problem = a + if a == 2: + solution = True + return (problem, solution) + if a % 2 == 0: + solution = False + return (problem, solution) + for i in range(3, a // 2 + 1, 2): + if a % i == 0: + solution = False + return (problem, solution) + solution = True + return (problem, solution) + + +is_prime = Generator('isprime', 74, 'a any positive integer', + 'True/False', isprime) +print(is_prime.func) diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index 2d0910f..bf59c56 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -94,3 +94,4 @@ from .degree_to_rad import * from .radian_to_deg import * from .differentiation import * from .definite_integral import * +from .isprime import * \ No newline at end of file diff --git a/mathgenerator/funcs/isprime.py b/mathgenerator/funcs/isprime.py new file mode 100644 index 0000000..9da7bfb --- /dev/null +++ b/mathgenerator/funcs/isprime.py @@ -0,0 +1,18 @@ +from .__init__ import * + + +def isprime(max_a=100): + a = random.randint(2, max_a) + problem = a + if a == 2: + solution = True + return (problem, solution) + if a % 2 == 0: + solution = False + return (problem, solution) + for i in range(3, a // 2 + 1, 2): + if a % i == 0: + solution = False + return (problem, solution) + solution = True + return (problem, solution)