All problems
Binomial Moments Mean Variance
Problem
A binomial(n, p) distribution has mean n p and variance n p (1 - p).
Given n and p, return [mean, variance].
Hint
Both moments are linear in n.
Test cases
case 1
in: [10,0.5]
expected: [5,2.5]
case 2
in: [100,0.01]
expected: [1,0.99]
case 3
in: [5,1]
expected: [5,0]
Starter codePython
def binomial_mean_and_variance(n, p):
# Your code here
pass3 test cases · run your code against them in the editor