def confidenceComparisonSamplesProblem(): try: n1 = random.randint(41, 50) n2 = random.randint(31, 40) u1 = random.randint(31, 40) u2 = random.randint(41, 50) s1 = random.randint(2, 5) s2 = random.randint(6, 9) pOptions = [0.2, 0.1, 0.05, 0.02, 0.01, 0.005] p = pOptions[random.randint(0, 5)] z = coursesFunctionsBll.normalDistributionInverse(1 - (p / 2)) sol = round(z * ((((s1**2) / n1) + ((s2**2) / n2))**0.5), 4) solution = r"" + str(abs(u1 - u2)) + r" \pm " + str(sol) + r"" question = r'In a software company the average age of programmers have standard deviation of ' + str( s1 ) + r' years, and for human resources they have a standard deviation of ' + str( s2 ) + r' years. \\ In a sample of ' + str( n1 ) + r' programmers the average age was ' + str( u1 ) + r' years, and in a sample of ' + str( n2 ) + r' human resources employees the average age was ' + str( u2 ) + r' years. \\ Find the confidence interval for the difference of height with a level of ' + str( round(100 * (1 - p), 2)) + r'\%. Choose the closest option: ' alternatives = coursesFunctionsBll.multipleOptions([sol], 5) tempAlternatives = [] for ta in range(5): tempAlternatives.append(r"" + str(abs(u1 - u2)) + r" \pm " + 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 confidenceProportionProblem(): try: n = random.randint(40, 60) u = random.randint(20, 30) pr = u / n pOptions = [0.2, 0.1, 0.05, 0.02, 0.01, 0.005] p = pOptions[random.randint(0, 5)] z = coursesFunctionsBll.normalDistributionInverse(1 - (p / 2)) sol1 = round(100 * pr, 4) sol2 = round(z * 100 * ((pr * (1 - pr) / n)**0.5), 4) solution = r"" + str(sol1) + r"\% \pm " + str(sol2) + r"\%" question = r'In colombia the police officers are being spied by a criminal organization, but the proportion is unknown. \\ A search founds that in a sample of ' + str( n ) + r' police officers they found that ' + str( u ) + r' police officers are spied . \\ Find the confidence limit with a ' + str( round(100 * (1 - p), 1) ) + r'\% for the real proportion of police officers spied (choose the closest option): ' alternatives = coursesFunctionsBll.percentageProportionOptions( [sol1, sol2], 5) tempAlternatives = [] for ta in range(5): tempAlternatives.append(r"" + str(alternatives[ta][0]) + r"\% \pm " + 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 confidenceBigSamplesProblem(): try: x = random.randint(50, 100) m = random.randint(150, 175) s = random.randint(5, 10) pOptions = [0.2, 0.1, 0.05, 0.02, 0.01, 0.005] p = pOptions[random.randint(0, 5)] z = coursesFunctionsBll.normalDistributionInverse(1 - (p / 2)) sol = round(z * s / (x**0.5), 4) solution = r"" + str(m) + r" \pm " + str(sol) + r"" question = r'A sample of ' + str( x ) + r' school girls give an average height of ' + str( m ) + r' cms and standard deviation of ' + str( s ) + r' cms. Find the confidence limit with a ' + str( round(100 * (1 - p), 1) ) + r'\% for the real height of all the school girls (choose the closest option): ' alternatives = coursesFunctionsBll.multipleOptions([sol], 5) tempAlternatives = [] for ta in range(5): tempAlternatives.append(r"" + str(m) + r" \pm " + 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 proportionSizeProblem1(): try: nn = random.randint(5000, 10000) p = random.randint(10, 90) / 100 q = 1 - p e = random.randint(5, 10) / 100 a = random.randint(1, 10) / 100 z = coursesFunctionsBll.normalDistributionInverse(1 - (a / 2)) sol = round((((z**2) * p * q * nn) + (nn * (e**2))) / ((nn * (e**2)) + ((z**2) * p * q))) solution = r"" + str(sol) + r"" question = r'In a city a previous study shows that ' + str( round(p * 100) ) + r'\% of population are fans of A team. A survey wants to comfirm this previous result. The city have ' + str( nn ) + r' citizens. Which should be the size of the sample for the new study for an error limit of ' + str( e) + r' and a significance level of ' + str(round( a * 100)) + r'\%. Choose the closest option: ' alternatives = coursesFunctionsBll.positiveArithmeticOptions([sol], 5, 10) 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 sampleSizeProblem(): try: p = random.randint(500, 1000) s = random.randint(100, 150) e = random.randint(20, 30) a = random.randint(1, 10) / 100 z = coursesFunctionsBll.normalDistributionInverse(1 - (a / 2)) sol = round( (z**2) * (s**2) * p / (((p - 1) * (e**2)) + ((z**2) * (s**2)))) solution = r"" + str(sol) + r"" question = r'A bank wants to know the average saving per client. A previous study shows the standard deviation on clients saving is \$' + str( s ) + r'. The bank has ' + str( p ) + r' clients. What should be the size of the sample for an error limit of ' + str( e) + r' and a significance level of ' + str(round( a * 100)) + r'\%. Choose the closest answer: ' alternatives = coursesFunctionsBll.positiveArithmeticOptions([sol], 5, 10) 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 proportionSizeProblem2(): try: p = random.randint(10, 90) / 100 q = 1 - p e = random.randint(5, 10) / 100 a = random.randint(1, 10) / 100 z = coursesFunctionsBll.normalDistributionInverse(1 - (a / 2)) sol = round(((z**2) * p * q) / (e**2)) solution = r"" + str(sol) + r"" question = r'An international statistical service founds that ' + str( round(p * 100) ) + r'\% of population in country B lives in poverty. A new research wants to comfirm the former conclusion. Which should be the size of the sample for the new study for a error limit of ' + str( e) + r' and a significance level of ' + str(round( a * 100)) + r'\%. Choose the closest option: ' alternatives = coursesFunctionsBll.positiveArithmeticOptions([sol], 5, 10) 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 sampleSizeProblem2(): try: s = random.randint(20, 30) e = random.randint(5, 10) a = random.randint(1, 10) / 100 z = coursesFunctionsBll.normalDistributionInverse(1 - (a / 2)) sol = round((z**2) * (s**2) / e**2) solution = r"" + str(sol) + r"" question = r'A research shows that average height of basketball players follows a normal distribution with standard deviation of ' + str( s ) + r' cms. If a research group wants to find the average size, what should be the size of the sample for an error limit of ' + str( e) + r' and a significance level of ' + str(round( a * 100)) + r'\% . Choose the closest option: ' alternatives = coursesFunctionsBll.positiveArithmeticOptions([sol], 5, 10) 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