Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-353

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
    pass

3 test cases · run your code against them in the editor