In n independent trials, each a success with probability p, what is the probability of exactly k successes?
Input
One line: n, k (whole numbers, 0 ≤ k ≤ n ≤ 100) and p (a decimal from 0 to 1).
Output
P(X = k) to 6 decimal places.
Examples
Example 1 · Input
10 5 0.5
Expected output
0.246094
Example 2 · Input
3 2 0.5
Expected output
0.375000
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
math.comb(n, k) counts the orders.
Hint 2
P(X = k) = comb(n, k) × p**k × (1 − p)**(n − k).
Solution
Show one correct solution (try it yourself first)
from math import comb
n, k, p = input().split()
n, k, p = int(n), int(k), float(p)
print(f"{comb(n, k) * p ** k * (1 - p) ** (n - k):.6f}")