From 91b23a4c666f2442db41aef480a7649c1be13c6e Mon Sep 17 00:00:00 2001 From: akash khamkar <49859828+xatriya@users.noreply.github.com> Date: Wed, 14 Oct 2020 23:13:33 +0530 Subject: [PATCH] new 1s binary complement generated added . new 1s binary complement problem generator added . --- mathgenerator/mathgen.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 96e9c47..6ffa7ba 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -50,6 +50,19 @@ def divisionFunc(maxRes = 99, maxDivid = 99): problem = str(a) + "/" + str(b) + "=" solution = str(c) return problem, solution + +def binary_1s_Complement(maxDigits = 10): + question = '' + answer = '' + for i in range(random.randint(1,maxDigits)): + temp = str(random.randint(0, 1)) + question += temp + answer += "0" if temp == "1" else "1" + + problem = question + solution = answer + return problem, solution + # || Class Instances #Format is: @@ -58,4 +71,5 @@ addition = Generator("Addition", 2, "a+b=", "c", additionFunc) subtraction = Generator("Subtraction", 3, "a-b=", "c", subtractionFunc) multiplication = Generator("Multiplication", 4, "a*b=", "c", multiplicationFunc) division = Generator("Division", 5, "a/b=", "c", divisionFunc) +binary_complement_1s = Generator("binary_complement_1s", 6, "(1010)=", "0101", binary_1s_Complement)