A disease affects a share prevalence of people. A test detects a sick person with probability sensitivity, and wrongly says positive for a healthy person with probability false_positive. Given a positive test, how likely is the person to be sick?
Input
One line: prevalence, sensitivity and false_positive, decimals between 0 and 1. At least one positive result is possible.
Output
P(sick | positive) to 4 decimal places.
Examples
Example 1 · Input
0.01 0.99 0.05
Expected output
0.1667
Example 2 · Input
0.5 0.9 0.1
Expected output
0.9000
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Count imaginary people: true positives = prevalence × sensitivity; false positives = (1 − prevalence) × false-positive rate.
Hint 2
P(sick | positive) = true positives ÷ all positives.
Solution
Show one correct solution (try it yourself first)
prev, sens, fp = map(float, input().split())
true_pos = prev * sens
false_pos = (1 - prev) * fp
print(f"{true_pos / (true_pos + false_pos):.4f}")