コード例 #1
0
def rationalInequations():
    try:
        a = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        opt1 = round(-b / a, 4)
        opt2 = round(-d / c, 4)
        max = opt1 if opt1 > opt2 else opt2
        min = opt1 if opt1 < opt2 else opt2
        mid = (min + max) / 2
        solution = r""
        if (((a * mid) + (b)) / ((c * mid) + (d)) > 0):
            solution = r"(" + str(min) + r", " + str(max) + r")"
        else:
            solution = r"(-\infty, " + str(min) + r") U (" + str(
                max) + r", \infty)"
        question = 'Which is the right domain for x in the next inequality?: [(' + str(
            a) + 'x)+(' + str(b) + ')]/[(' + str(c) + 'x)+(' + str(d) + ')]>0'
        options = coursesFunctionsBll.inequationsDomain(min, max)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #2
0
def inequationTwoSides():
    try:
        a = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        e = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        sol1 = ((a * d) - c) / b
        sol2 = ((e * d) - c) / b
        solution = 'no'
        if ((sol1 <= sol2 and b * c > 0) or (sol1 >= sol2 and b * c < 0)):
            solution = 'yes'
        question = 'for the next inequation, has x any valid solution?: ' + str(
            a) + '<=[(' + str(b) + 'x)+(' + str(c) + ')]/(' + str(
                d) + ')<=' + str(e)
        options = json.loads(json.dumps({"a": "yes", "b": "no"}))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #3
0
def firstGradeEquation():
    try:
        divisor1 = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        dividend1 = random.randint(1, 10)
        divisor3 = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        dividend3 = random.randint(1, 10)
        allDividend = (divisor1 / dividend1) - (divisor3 / dividend3)
        if (allDividend == 0):
            return firstGradeEquation()
        divisor2 = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        dividend2 = random.randint(1, 10)
        divisor4 = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        dividend4 = random.randint(1, 10)
        allDivisor = (divisor4 / dividend4) - (divisor2 / dividend2)
        sol = allDivisor / allDividend
        question = "(" + str(divisor1) + "x/" + str(dividend1) + ")+(" + str(
            divisor2) + "/" + str(dividend2) + ")=(" + str(
                divisor3) + "x/" + str(dividend3) + ")+(" + str(
                    divisor4) + "/" + str(dividend4) + ")"
        solution = round(sol, 4)
        options = coursesFunctionsBll.generateOptions(solution)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #4
0
def inequations1():
    a = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
    b = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
    c = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
    d = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
    e = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
    f = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
    if (((a * f) - (d * c)) == 0):
        return inequations1()
    question = 'let x alone in the next inequality [(' + str(a) + 'x)+(' + str(
        b) + ')]/(' + str(c) + ') <= [(' + str(d) + 'x)+(' + str(
            e) + ')]/(' + str(f) + ')'
    sol = round(((e * c) - (b * f)) / ((a * f) - (d * c)), 4)
    solution = 'x' + ('<=' if
                      (((a * f) - (d * c)) * c * f >= 0) else '>=') + str(sol)
    options = coursesFunctionsBll.inequationsAlternatives1(sol)
    jsonResponse = json.dumps({
        "question":
        coursesFunctionsBll.replaceSpace(question),
        "solution":
        coursesFunctionsBll.replaceSpace(solution),
        "options":
        coursesFunctionsBll.replaceOptions(options)
    })
    return [jsonResponse]
コード例 #5
0
def areaProblem():
    try:
        a = random.randint(1, 100)
        b = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(10, 100) * (-1)
        question = 'if a rectangle area is ' + str(
            -1 * c) + ', its height is h and its width is equal to (' + str(
                a) + 'h)+(' + str(
                    b) + '), which is the perimeter of this rectangle?:'
        solution1 = (-b + ((b * b) - (4 * a * c))**(0.5)) / (2 * a)
        solution2 = (-b - ((b * b) - (4 * a * c))**(0.5)) / (2 * a)

        solution = round((solution1 + (solution1 * a) + b) *
                         2, 4) if solution1 > 0 else round(
                             (solution2 + (solution2 * a) + b) * 2, 4)
        options = coursesFunctionsBll.generateOptions(solution)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #6
0
def seriesProblem():
    try:
        addNumber = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        opNumber = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        a = random.randint(1, 3)
        sequence = []
        if (a == 1):
            for x in range(6):
                sequence.append(addNumber + (opNumber * (x)))
        elif (a == 2):
            for x in range(6):
                sequence.append(addNumber + (opNumber**(x)))
        else:
            for x in range(6):
                sequence.append(addNumber + ((x)**abs(opNumber)))
        subList = [str(sequence[index]) for index in range(5)]
        question = "which is the next number in the series " + (
            ', '.join(subList)) + "..."
        sol = sequence[5]
        solution = str(sol)
        options = coursesFunctionsBll.alternativesSequence(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #7
0
def toInfiniteLimitProblem2():
    try:
        a = random.randint(1, 8) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 8) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 8) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 8) * (random.randint(0, 1) * 2 - 1)
        if a == c:
            toInfiniteLimitProblem2()
        solution = ''
        if d < 0:
            solution = '0'
        elif d % 2 != 0:
            solution = 'undefined'
        else:
            solution = 'inf' if ((c - a)**b) > 0 else '-inf'
        question = "[lim x->(" + str(c) + ")] for [(x-(" + str(
            a) + "))^(" + str(b) + ")]/[(x-(" + str(c) + "))^(" + str(d) + ")]"
        options = json.loads(
            json.dumps({
                'a': 'inf',
                'b': '-inf',
                'c': 'undefined',
                'd': '0'
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #8
0
def absoluteValue1():
    try:
        a = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        e = random.randint(1, 100)
        sol1 = ((d * e) - b) / (a - (e * c))
        sol2 = ((d * (-e)) - b) / (a - ((-e) * c))
        solution = '' + str(round(sol1, 4)) + ',' + str(round(sol2, 4)) + ''
        question = 'which are the two solutions for |[(' + str(
            a) + 'x)+(' + str(b) + ')]/[(' + str(c) + 'x)+(' + str(
                d) + ')]|=' + str(e) + ''
        options = coursesFunctionsBll.absoluteValue1(
            [round(sol1, 4), round(sol2, 4)])
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #9
0
def infiniteLimitProblem2():
    try:
        a = random.randint(1, 5)
        b = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        e = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        f = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        g = random.randint(1, 5)
        sol = round((a**(0.5)) / c, 4)
        solution = str(sol)
        question = "[Lim x->inf] for [((" + str(a) + "x^" + str(
            2 * g) + ")+(" + str(b) + "x))^(1/2)]((" + str(e) + "x)+(" + str(
                f) + "))/((" + str(c * e) + "x^" + str(g + 1) + ")+(" + str(
                    c * f) + "x^" + str(g) + ")+(" + str(e * d) + "x)+(" + str(
                        d * f) + "))"
        options = coursesFunctionsBll.generateOptions(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #10
0
def toInfiniteLimitProblem():
    try:
        a = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(0, 2)
        if c == b:
            toInfiniteLimitProblem()
        solution = ''
        if d == 0:
            solution = 'undefined'
        else:
            solution = 'inf' if a > 0 else '-inf'
            c = b
        question = "[lim x->(" + str(b) + ")] for (" + str(
            a) + ")/(x^2+(" + str(-b - c) + "x)+(" + str(b * c) + "))"
        options = json.loads(
            json.dumps({
                'a': 'inf',
                'b': '-inf',
                'c': 'undefined'
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #11
0
def infiniteLimitProblem():
    try:
        a = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        e = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        f = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        g = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        h = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        sol = round(((a * g) + (c * e)) / (c * g), 4)
        solution = str(sol)
        question = "[Lim x->inf] for ((" + str(a) + "x)+(" + str(
            b) + "))/((" + str(c) + "x)+(" + str(d) + ")) + ((" + str(
                e) + "x)+(" + str(f) + "))/((" + str(g) + "x)+(" + str(
                    h) + "))"
        options = coursesFunctionsBll.generateOptions(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #12
0
def productGeometricProblem():
    try:
        a = random.randint(5, 8)
        b = random.randint(2, 4) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(2, 5) * (random.randint(0, 1) * 2 - 1)
        #sol= (((b*c)*(b*(c**a)))**a)**(0.5)
        sol = (b**a) * (c**sum(list(range(1, a + 1))))
        #sol =  int(format(sol,'.53g'))
        items = []
        for x in range(4):
            items.append(b * (c**(x + 1)))
        question = "The first four elements of a series are " + str(
            items[0]) + "," + str(items[1]) + "," + str(items[2]) + "," + str(
                items[3]) + ", which is the product of the first " + str(
                    a) + " items?:"
        solution = str(sol)
        options = coursesFunctionsBll.generateOptions(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #13
0
def nGeometricProblem():
    try:
        a = random.randint(10, 20)
        b = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(2, 5) * (random.randint(0, 1) * 2 - 1)
        sol = b + (c**a)
        items = []
        for x in range(5):
            items.append(b + (c**(x + 1)))
        question = "The first five element of a series are " + str(
            items[0]) + "," + str(items[1]) + "," + str(items[2]) + "," + str(
                items[3]) + "," + str(
                    items[4]) + ", which is the value of the " + str(
                        a) + "th item?:"
        solution = str(sol)
        options = coursesFunctionsBll.generateOptions(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #14
0
def geometricSeriesProblem():
    try:
        a = random.randint(5, 10)
        b = random.randint(1, 5) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 5)
        d = random.randint(1, 5)
        if (c == d):
            return geometricSeriesProblem()
        sol = round((b * (c / d)) * (((c / d)**a) - 1) / ((c / d) - 1), 4)
        question = "Which is the sum of the first " + str(
            a) + " terms (from n=1 to n=" + str(
                a) + ") in the function (" + str(b) + "*((" + str(
                    c) + "/" + str(d) + ")^x)): "
        solution = str(sol)
        options = coursesFunctionsBll.generateOptions(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #15
0
def squareLimitProblem():
    try:
        a = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(0, 2)
        if a == (c * c):
            squareLimitProblem()
        solution = ''
        if d == 0:
            solution = '0'
            a = c * c
        else:
            solution = 'inf' if a > (c * c) else '-inf'
        question = "[lim x->(inf)] for ((" + str(a) + "x^2)-(" + str(
            b) + "))^(1/2)-(" + str(c) + "x)"
        options = json.loads(json.dumps({'a': 'inf', 'b': '-inf', 'c': '0'}))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #16
0
def firstGradeTwoVariables():
    try:
        xDivisor = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        xDividend = random.randint(1, 10)
        cDivisor = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        cDividend = random.randint(1, 10)
        components = [
            xDividend * cDividend, -1 * xDividend * cDivisor,
            cDividend * xDivisor
        ]
        question = 'for f(x)=(' + str(xDivisor) + 'x/' + str(
            xDividend) + ')+(' + str(cDivisor) + '/' + str(
                cDividend) + ') find f(x)^(-1)'
        solution = '[(' + str(xDividend * cDividend) + 'y+(' + str(
            -1 * xDividend * cDivisor) + ')]/(' + str(
                cDividend * xDivisor) + ')=x'
        options = coursesFunctionsBll.generateTwoVariableOptions(components)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #17
0
def trigonometryLimitProblem2():
    try:
        a = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 10)
        c = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 10)
        e = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        if (a * d) + (
                c * b
        ) == 0:  # avoid solution equals 0 since this will be a problem generating the options
            return trigonometryLimitProblem2()
        sol = round(((a * d) + (b * c)) / e, 4)
        solution = str(sol)
        question = "[lim x->(0)] for [((" + str(a) + "x)+(" + str(
            b) + "))((" + str(c) + "x)+(" + str(d) + "))-((" + str(
                b * d) + ")*cos(" + str(e) + "x))]/(" + str(e) + "x)"
        options = coursesFunctionsBll.generateOptions(sol)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #18
0
def absoluteValue2():
    try:
        a = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 100) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 100)
        solPos = round(((d * c) - b) / a if a * c > 0 else
                       (((-d) * c) - b) / a, 4)
        solNeg = round((((-d) * c) - b) / a if a * c > 0 else
                       ((d * c) - b) / a, 4)
        solution = ''
        if (solNeg > solPos):
            solution = '(null)'
        else:
            solution = '' + str(solNeg) + '<x<' + str(solPos) + ''
        question = 'get valid range for x in |[(' + str(a) + 'x)+(' + str(
            b) + ')]/(' + str(c) + ')|<' + str(d) + ''
        options = coursesFunctionsBll.absoluteValue2([solNeg, solPos])
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #19
0
def inequations2():
    try:
        a = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        b = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        d = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        e = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        f = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        g = random.randint(1, 10) * (random.randint(0, 1) * 2 - 1)
        sola = (d * c) - (b * f)
        solb = (e * c) - (b * g)
        solc = a * f
        sold = a * g
        solution = 'x' + (
            '<=' if a * c > 0 else '>=') + '[(' + str(sola) + 'y)+(' + str(
                solb) + ')]/[(' + str(solc) + 'y)+(' + str(sold) + ')]'
        question = 'let x alone in the next inequality [(' + str(
            a) + 'x)+(' + str(b) + ')]/(' + str(c) + ') <= [(' + str(
                d) + 'y)+(' + str(e) + ')]/[(' + str(f) + 'y)+(' + str(
                    g) + ')]'
        options = coursesFunctionsBll.inequationsAlternatives2(
            [sola, solb, solc, sold])
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #20
0
def parallelProblem():
    try:
        x0 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        y0 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        x1 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        y1 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        x2 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        y2 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        if x2 == x1:
            return parallelProblem()
        slope = round((y2 - y1) / (x2 - x1), 4)
        intersection = round(y0 - (x0 * slope), 4)
        solution = "y=(" + str(slope) + "x)+(" + str(intersection) + ")"
        question = "which is the straight line which pass through the point (" + str(
            x0
        ) + "," + str(
            y0
        ) + ") and is parallel to the straigh line which pass through the points (" + str(
            x1) + "," + str(y1) + ") and (" + str(x2) + "," + str(y2) + "): "
        options = coursesFunctionsBll.parallelProblemOptions(
            slope, intersection)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #21
0
def quadrilateralProblem():
    try:
        c1 = random.randint(1, 45)
        c2 = random.randint(1, 45)
        a1 = random.randint(2, 10)
        a2 = random.randint(2, 10)
        sol = round((180 - (c1 + c2)) / (a1 + a2), 4)

        solution = r"" + str(sol)
        question = r"A quadrilateral incribed in a circle has inner opposite angles A and B, where A degrees are " + str(
            a1) + r"x+" + str(c1) + r" and B degrees are " + str(
                a2) + r"x+" + str(c2) + r". Which is the value of x?:"
        alternatives = coursesFunctionsBll.multipleOptions([sol], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #22
0
def circleProblem():
    try:
        x0 = random.randint(2, 19) * (random.randint(0, 1) * 2 - 1)
        y0 = random.randint(2, 19) * (random.randint(0, 1) * 2 - 1)
        x1 = random.randint(2, 19) * (random.randint(0, 1) * 2 - 1)
        y1 = random.randint(2, 19) * (random.randint(0, 1) * 2 - 1)
        r = (((x1 - x0)**2) + ((y1 - y0)**2))**(1 / 2)
        perimeter = round(2 * 3.1416 * r, 4)
        area = round(3.1416 * r * r, 4)
        solution = "Perimeter= " + str(perimeter) + " and Area=" + str(area)
        question = "Find the perimeter and area of the circle which center is (" + str(
            x0) + "," + str(y0) + ") and pass through the point (" + str(
                x1) + "," + str(y1) + "): "
        options = coursesFunctionsBll.perimeterAreaOptions(perimeter, area)
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #23
0
def tangencyPointProblem():
    try:
        d = random.randint(11, 20)
        t = random.randint(21, 30)
        x = ((t**2) - (d**2)) / (2 * d)
        sol = round(x + d, 4)
        solution = r"" + str(sol)
        question = r"You are walking towards a circular swimming pool. At some moment you are standing " + str(
            d
        ) + r"ft from the border, while your distance to the point of tangency is " + str(
            t) + r"ft. How many ft are you from the center of the pool?: "
        alternatives = coursesFunctionsBll.multipleOptions([sol], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #24
0
def ellipseAreaProblem():
    try:
        x01 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        x02 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        y0 = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        minor = random.randint(2, 10)
        if x01 == x02:
            return ellipseProblem()
        x0 = (x01 + x02) / 2  #HERE IS X0
        major = ((x01 - x0)**2 + (minor)**2)**(1 / 2)
        area = round(3.1416 * minor * major, 4)
        solution = str(area)
        options = coursesFunctionsBll.generateOptions(area)
        question = "which is the area of ellipse which focus on (" + str(
            x01) + "," + str(y0) + ") (" + str(x02) + "," + str(
                y0) + ") and minor semiaxis equal to " + str(minor) + ""
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #25
0
def circleTanProblem():
    try:
        x = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        y = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        m = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        c = random.randint(2, 10) * (random.randint(0, 1) * 2 - 1)
        slope = -1 / m
        intersection = y - (x * slope)
        x1 = (intersection - c) / (m - slope)
        y1 = (x1 * m) + c
        distance = ((x1 - x)**2 + (y1 - y)**2)**(1 / 2)
        diameter = round(distance * 2, 4)
        solution = str(diameter)
        options = coursesFunctionsBll.generateOptions(diameter)
        question = "which is the diameter of a circle where center is in (" + str(
            x) + "," + str(y) + ") and is tangent to the line y=(" + str(
                m) + "x)+(" + str(c) + ")"
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #26
0
def parabolaProblem():
    try:
        focusx = random.randint(2, 20) * (random.randint(0, 1) * 2 - 1)
        focusy = random.randint(2, 20) * (random.randint(0, 1) * 2 - 1)
        directrix = (random.randint(2, 20) * (random.randint(0, 1) * 2 - 1))
        if (directrix >= focusy):
            parabolaProblem()
        c1 = round((focusy + directrix) / 2, 4)
        c2 = round(1 / (2 * (abs(focusy - directrix))), 4)
        c3 = focusx
        solution = "y-(" + str(c1) + ")=" + str(c2) + "*(x-(" + str(
            c3) + "))^2"
        options = coursesFunctionsBll.parabolaProblemOptions([c1, c2, c3])
        question = "which is the canonical equation of the parabola which focus (" + str(
            focusx) + "," + str(focusy) + ")  directrix y=" + str(
                directrix) + ":"
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #27
0
def circleRegularPolygonProblem2():
    try:
        x = random.randint(10, 20)
        s = random.randint(3, 10)
        angle = (s - 2) * 180 / (s * 2)
        h = (x / 2) * math.tan(angle * math.pi / 180)
        area = round(math.pi * h * h, 4)
        solution = r"" + str(area)
        question = r"For a regular polygon of " + str(
            s) + " sides, where each side have a length of " + str(
                x
            ) + r", find the area of the circle inscribed in this polygon: "
        alternatives = coursesFunctionsBll.multipleOptions([area], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #28
0
def differenceMeansProblem2():
    try:
        n1 = random.randint(30, 40)
        n2 = random.randint(30, 40)
        x1 = round(random.randint(2500, 3000) / 10, 2)
        x2 = round(
            x1 + (random.randint(10, 20) *
                  ((random.randint(0, 1) * 2) - 1) / 10), 2)
        s1 = round(random.randint(50, 100) / 10, 2)
        s2 = round(s1 / random.randint(12, 15), 2)
        pOptions = [0.2, 0.1, 0.05, 0.02, 0.01, 0.005]
        p = pOptions[random.randint(0, 5)]
        v1 = round(s1**2, 2)
        v2 = round(s2**2, 2)
        g = (((v1 / n1) + (v2 / n2))**2) / ((((v1 / n1)**2) / (n1 - 1)) +
                                            (((v2 / n2)**2) / (n2 - 1)))
        g = math.floor(g)
        t = abs(coursesFunctionsBll.tStudentAprox(p / 2, g))
        #tc=(x1-x2)/((v1/n1)+(v2/n2))
        co = ((v1 / n1) + (v2 / n2))**0.5
        sol1 = round((x1 - x2) - (t * co), 4)
        sol2 = round((x1 - x2) + (t * co), 4)
        solution = r"Not enough evidence that means are different"
        if (sol1 > 0 and sol2 > 0) or (sol1 < 0 and sol2 < 0):
            solution = r"Enough evidence that means are different"
        question = r'An electric circuit factory wants to compare the current flow with two designs. For the first design they use a sample of \\ ' + str(
            n1
        ) + ' and found a mean of ' + str(
            x1
        ) + ' current flow with a variance of ' + str(
            v1
        ) + '. For the second design they use a sample\\ of ' + str(
            n2
        ) + ' and found a mean of ' + str(
            x2
        ) + ' current flow with a variance of ' + str(
            v2
        ) + '. The analysis using the f distribution \\ with a significance level of ' + str(
            round(p * 100, 2)
        ) + r'\% shows enough evidence that variance with the two designs are different.  Use the confidence interval for difference of means \\with a significance level of ' + str(
            round(p * 100, 2)
        ) + r'\%, find if there is enogh evidence to suggest that means are different: '
        options = json.loads(
            json.dumps({
                'a': r"Not enough evidence that means are different",
                'b': r"Enough evidence that means are different",
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #29
0
def hyperGeometricDistributionProblem():
    try:
        nk = random.randint(32, 64)
        nx = random.randint(8, 16)
        k = random.randint(8, 16)
        x = random.randint(2, 4)
        x2 = random.randint(2, 4)
        sol1 = round(
            coursesFunctionsBll.binomialCoefficient(k, x) *
            (coursesFunctionsBll.binomialCoefficient(nk - k, nx - x) * 100 /
             coursesFunctionsBll.binomialCoefficient(nk, nx)), 4)
        sol2 = 0
        i = 0
        while i < x2:
            sol2 += coursesFunctionsBll.binomialCoefficient(k, i) * (
                coursesFunctionsBll.binomialCoefficient(nk - k, nx - i) * 100 /
                coursesFunctionsBll.binomialCoefficient(nk, nx))
            i += 1
        sol2 = round(sol2, 4)
        solution = r"a) " + str(sol1) + r"\%, b) " + str(sol2) + r"\%"
        question = r"A glasses factory for this month make " + str(
            nk
        ) + r" glasses, the quality engineer finds that " + str(
            k
        ) + r" glasses are broken. for a group of " + str(
            nx
        ) + r" glasses randomly chosen a) which is the probability that " + str(
            x) + r" glasses are broken b) less than " + str(
                x2) + r" glasses are broken: "
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions(
            [sol1, sol2], 5, 1)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"a) " + str(alternatives[ta][0]) +
                                    r"\%, b) " + str(alternatives[ta][1]) +
                                    r"\%")
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er
コード例 #30
0
def cosineTheoremProblem():
    try:
        a = random.randint(16, 20)
        b = random.randint(16, 20)
        c = random.randint(21, 30)

        angle_a = round(
            math.acos(
                ((a**2) - (b**2) - (c**2)) / (-2 * b * c)) * (180 / math.pi),
            4)
        angle_b = round(
            math.acos(
                ((b**2) - (a**2) - (c**2)) / (-2 * a * c)) * (180 / math.pi),
            4)
        angle_c = round(
            math.acos(
                ((c**2) - (b**2) - (a**2)) / (-2 * b * a)) * (180 / math.pi),
            4)

        optQuestions = [[r"x", angle_a], [r"y", angle_b], [r"z", angle_c]]
        quest = optQuestions[random.randint(0, 2)]

        solution = r"" + str(quest[1])
        question = r"a triangle have side A of length " + str(
            a
        ) + r" and opposite angle x, side B of length " + str(
            b
        ) + r" and opposite angle y, side C of length " + str(
            c
        ) + r" and opposite angle z. Find the value (in degrees) of " + str(
            quest[0]) + r": "
        alternatives = coursesFunctionsBll.multipleTrigonometricOptions(
            [quest[1]], 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]))
        options = json.loads(
            json.dumps({
                'a': tempAlternatives[0],
                'b': tempAlternatives[1],
                'c': tempAlternatives[2],
                'd': tempAlternatives[3],
                'e': tempAlternatives[4]
            }))
        jsonResponse = json.dumps({
            "question":
            coursesFunctionsBll.replaceSpace(question),
            "solution":
            coursesFunctionsBll.replaceSpace(solution),
            "options":
            coursesFunctionsBll.replaceOptions(options)
        })
        return [jsonResponse]
    except Exception as er:
        return er