Esempio n. 1
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
Esempio n. 2
0
def pascalDistributionProblem():
    try:
        x = random.randint(1, 5)  #success
        r = random.randint(6, 10)  #fails
        p = (random.randint(3, 4) + (random.randint(0, 1) * 3)) / 10
        q = 1 - p
        sol1 = round(
            math.factorial(x + r - 1) * (q**(x)) * (p**(r)) * 100 /
            (math.factorial(r - 1) * math.factorial(x)), 4)
        x2 = random.randint(1, 5)
        r2 = random.randint(6, 10)
        sol2 = 0
        i = 0
        while i <= (x2):
            sol2 += round(
                math.factorial(i + r2 - 1) * (q**(i)) * (p**(r2)) * 100 /
                (math.factorial(r2 - 1) * math.factorial(i)), 4)
            i += 1
        sol2 = round(100 - sol2, 4)
        solution = r"a) " + str(sol1) + r"\%, b) " + str(sol2) + r"\%"
        question = r"The probability of a soccer player to fail a score opportunity is " + str(
            round(p * 100)
        ) + r"\%. a) which is the probability that the player achieve his " + str(
            r) + r"th fail in the " + str(
                x + r) + r"th opportunity b) for achieve his " + str(
                    r2) + r"th fail he needs more than " + str(
                        x2 + r2) + r" opportunities:"
        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
Esempio n. 3
0
def bayesTheoremProblem():
    try:
        a = 0.1
        b = 0.1
        c = 0.1
        for i in range(70):
            d = random.randint(0, 2)
            a = a + (0.01 if d == 0 else 0)
            b = b + (0.01 if d == 1 else 0)
            c = c + (0.01 if d == 2 else 0)
        fa = random.randint(10, 20) / 100
        fb = random.randint(10, 20) / 100
        fc = random.randint(10, 20) / 100
        sol1 = round(100 * (1 - (fc * c / ((fa * a) + (fb * b) + (fc * c)))),
                     4)
        sol2 = round(
            100 * ((1 - fb) * b / (1 - (fa * a) - (fb * b) - (fc * c))), 4)
        solution = r"a) " + str(sol1) + r"\%, b) " + str(sol2) + r"\%"
        question = r"Three machines, A, B and C produce " + str(
            round(a * 100)
        ) + r"\%, " + str(round(b * 100)) + r"\% and " + str(
            round(c * 100)
        ) + r"\% of total items. Percentage of broken production for this machines are " + str(
            round(fa * 100)
        ) + r"\%, " + str(round(fb * 100)) + r"\% and " + str(
            round(fc * 100)
        ) + r"\%.\\ If you choose a random produced item  a) which is the probability of don't get a machine C item if the item is broken, b) get a machine B item if the item is not 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
def averageComparisonProblem():
    try:
        x = random.randint(70, 90)
        y = x + (random.randint(1, 5) * ((random.randint(0, 1) * 2) - 1))
        sx = random.randint(5, 10)
        sy = random.randint(5, 10)
        nx = random.randint(35, 40)
        ny = nx + (random.randint(1, 5) * ((random.randint(0, 1) * 2) - 1))
        d = random.randint(1, 10) / 10
        v = ((sx**2) / nx) + ((sy**2) / ny)
        sol = round(
            (1 - coursesFunctionsBll.normalDistributionAprox(d, (x - y), v)) *
            100, 4)
        solution = r"" + str(sol) + r"\%"
        question = r'The average argentine lives ' + str(
            x
        ) + r' years, with standard deviation of ' + str(
            sx
        ) + r' years, while the average chilean lives ' + str(
            y
        ) + r' years, with standard deviation of ' + str(
            sy
        ) + r' years. If we make a sample of ' + str(
            nx
        ) + r' argentines and another samples whith ' + str(
            ny
        ) + r' chileans, which is the probability that argentine sample in average lives at least ' + str(
            d) + r' years more than chilean sample? choose closest option: '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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
def normalSampleFiniteProblem():
    try:
        nn = random.randint(50, 100)
        n = random.randint(5, 10)
        m = random.randint(100, 110)
        d = random.randint(1, 6)
        x = m - d
        v = random.randint(50, 60)
        v1 = (v / n) * ((nn - n) / (nn - 1))
        sol = round(
            (1 - (2 * coursesFunctionsBll.normalDistributionAprox(x, m, v1))) *
            100, 4)
        solution = r"" + str(sol) + r"\%"
        question = r'In a little village with ' + str(
            nn
        ) + r' houses,  the average size of a house is ' + str(
            m
        ) + r' mts^{2}, with a variance of ' + str(
            v
        ) + r' mts^{2}. For a sample of ' + str(
            n
        ) + ' different houses, find the probability that sample average size is between ' + str(
            m - d) + r' mts^{2} and ' + str(
                m + d
            ) + r' mts^{2}. Choose the option closer to the right solution: '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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
def proportionComparisonProblem():
    try:
        x = random.randint(40, 60) / 100
        y = x + ((random.randint(1, 5) *
                  ((random.randint(0, 1) * 2) - 1)) / 100)
        nx = random.randint(35, 40)
        ny = nx + (random.randint(1, 5) * ((random.randint(0, 1) * 2) - 1))
        d = random.randint(1, 5) / 100
        v = ((x * (1 - x)) / nx) + ((y * (1 - y)) / ny)
        sol = round(
            (coursesFunctionsBll.normalProportionAprox(d,
                                                       (x - y), v)) * 100, 4)
        solution = r"" + str(sol) + r"\%"
        question = r'The ' + str(
            round(x * 100)
        ) + r'\% of ferrari cars are red color, while ' + str(
            round(y * 100)
        ) + r'\% of williams cars are red. For a sample of ' + str(
            nx
        ) + r' ferrari cars and a sample of ' + str(
            ny
        ) + r' williams cars, which is the probability that ferrari sample percentage of red cars is not more than ' + str(
            round(d * 100)
        ) + r'\% above the percentage of red cars in williams sample. Choose closest option: '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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
def proportionFiniteProblem():
    try:
        nn = random.randint(500, 1000)
        n = random.randint(50, 100)
        m = random.randint(10, 90) / 100
        d = random.randint(1, 5) / 100
        x = m - d
        v = ((m * (1 - m)) / n) * ((nn - n) / (nn - 1))
        sol = round(
            (1 -
             (2 *
              (0.5 - coursesFunctionsBll.normalProportionAprox(x, m, v)))) *
            100, 4)
        solution = r"" + str(sol) + r"\%"
        question = r'In Mexico City the ' + str(
            round(m * 100)
        ) + r'\% hospitals report losses last year. If this city have a total of ' + str(
            nn
        ) + r' hospitals and a research study make a sample of ' + str(
            n
        ) + ' different hospitals, find the probability that the percentage of hospitals in the sample which report losses last year is not between ' + str(
            round((m - d) * 100)) + r'\% and ' + str(round(
                (m + d) *
                100)) + r'\%. Choose the option closer to the right solution: '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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
def normalSampleInfiniteProblem():
    try:
        n = random.randint(5, 10)
        x = random.randint(144, 150)
        m = x
        while m == x:
            m = random.randint(144, 150)
        v = random.randint(40, 50)
        v1 = v / n
        sol = round(
            (1 - coursesFunctionsBll.normalDistributionAprox(x, m, v1)) * 100,
            4)
        solution = r"" + str(sol) + r"\%"
        question = r'Average height for school students in New York is ' + str(
            m
        ) + r' cms, with a variance of ' + str(
            v
        ) + r' cms. For a sample of ' + str(
            n
        ) + ' students, find the probability that sample average height is above ' + str(
            x) + r' cms. Choose the option closer to the right solution: '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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
Esempio n. 9
0
def geometryDistributionProblem():
    try:
        x = random.randint(2, 10)
        y = random.randint(2, 10)
        p = random.randint(1, 9) / 100
        q = 1 - p
        sol1 = round((q**(x - 1)) * p * 100, 4)
        sol2 = 0
        i = 1
        while i < y:
            sol2 += (q**(i - 1)) * p * 100
            i += 1
        sol2 = round(sol2, 4)
        solution = r"a) " + str(sol1) + r"\%, b) " + str(sol2) + r"\%"
        question = r"The probability to call a station radio and get a response is " + str(
            round(p * 100)
        ) + r"\%. a) which is the probability to call and only get a response until the call number " + str(
            x) + r", b) get your first response on less than " + str(
                y) + r" calls:"
        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
def normalDistributionProblem():
    try:
        x = random.randint(14, 20)
        m = x
        while m == x:
            m = random.randint(14, 20)
        v = random.randint(4, 10)
        sol = round(
            coursesFunctionsBll.normalDistributionAprox(x, m, v) * 100, 4)
        solution = r"" + str(sol) + r"\%"
        question = r'The average salary in google is ' + str(
            m
        ) + ' thousand dollars, with a variance of \$' + str(
            v
        ) + ' thousand. If distribution follows a normal distribution, which percentage of google employeers get a salary below \$' + str(
            x) + ' thousand. Choose the option closer to the right solution: '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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
def sampleProportionProblem():
    try:
        a = random.randint(10, 90) / 100
        x = a + (random.randint(1, 5) / 100 * ((random.randint(0, 1) * 2) - 1))
        n = random.randint(25, 50)
        v = (a * (1 - a)) / n
        sol = round(
            (1 - coursesFunctionsBll.normalProportionAprox(x, a, v)) * 100, 4)
        solution = r"" + str(sol) + r"\%"
        question = r'In Colombia ' + str(
            round(a * 100)
        ) + r'\% of citizens think that president is doing a great job. If you make a sample of ' + str(
            n
        ) + r' citizens a) which is the probability that more than ' + str(
            round(x * 100)
        ) + r'\% of sample thinks the same way (choose the closest option): '
        alternatives = coursesFunctionsBll.arithmeticPercentageOptions([sol],
                                                                       5, 5)
        tempAlternatives = []
        for ta in range(5):
            tempAlternatives.append(r"" + str(alternatives[ta][0]) + 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