diff --git a/README.md b/README.md index 4f6ab56..1500dac 100644 --- a/README.md +++ b/README.md @@ -135,4 +135,4 @@ problem, solution = mathgen.genById(0) | 101 | Leap Year or Not | Year 2049 | is not a leap year | is_leap_year | | 102 | Minute to Hour conversion | Convert 960 minutes to Hours & Minutes | 16 hours and 0 minutes | minutes_to_hours | | 103 | Decimal to Binary Coded Decimal | BCD of Decimal Number 6561 is = | 19101 | decimal_to_bcd | -| 104 | Circumference | Circumference of circle with radius 11 | 69.14285714285714 | circumference | +| 104 | Circumference | Circumference of circle with radius 11 | 69.14285714285714 | circumference | \ No newline at end of file diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index de8ff5c..292ca1f 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -110,3 +110,4 @@ from .minutes_to_hours import * from .decimal_to_bcd import * from .circumference import * from .combine_like_terms import * +from .conditional_probability import * \ No newline at end of file diff --git a/mathgenerator/funcs/conditionalProbability.py b/mathgenerator/funcs/conditionalProbability.py new file mode 100644 index 0000000..88feb0b --- /dev/null +++ b/mathgenerator/funcs/conditionalProbability.py @@ -0,0 +1,25 @@ +from .__init__ import * + + +def conditionalProbFunc(): + P_disease = round(2. * random.random(), 2) + true_positive = round(random.random() + float(random.randint(90, 99)), 2) + true_negative = round(random.random() + float(random.randint(90, 99)), 2) + + def BayesFormula(P_disease, true_positive, true_negative): + P_notDisease = 100. - P_disease + false_positive = 100. - true_negative + P_plus = (P_disease) * (true_positive) + (P_notDisease) * (false_positive) + P_disease_plus = ((true_positive) * (100 * P_disease)) / P_plus + + return P_disease_plus + + problem = "Someone tested positive for a nasty disease which only {0:.2f}% of population have. " \ + "Test sensitivity (true positive) is equal to SN= {1:.2f}% whereas test specificity (true negative) SP= {2:.2f}%. " \ + "What is the probability that this guy really has that disease?".format(P_disease, true_positive, true_negative) + answer = str(round(BayesFormula(P_disease, true_positive, true_negative), 2)) + "%" + + return problem, answer + + +conditionalProb = Generator("Conditional Probability", 101, "P(A|+)=", "c", conditionalProbFunc) diff --git a/test.py b/test.py index 9377b5d..f1f0e5d 100644 --- a/test.py +++ b/test.py @@ -2,13 +2,12 @@ from mathgenerator import mathgen # test your generators here -print(mathgen.addition()) +# print(mathgen.addition()) # prints each generator in genList -list = mathgen.getGenList() -for item in list: - print(item[2]) +# list = mathgen.getGenList() +# for item in list: +# print(item[2]) # print(mathgen.getGenList()) -print(mathgen.decimal_to_roman_numerals()) -print(mathgen.genById(105)) +print(mathgen.genById(101)) \ No newline at end of file