All problems
Required Sample Size for Mean
Problem
Return the smallest integer n with z*sigma/sqrt(n) <= margin, which is ceil((z*sigma/margin)^2). Return 0 if margin <= 0 or sigma <= 0.
Hint
Solve the margin-of-error inequality for n and round up.
Test cases
case 1
in: [1.96,2,0.5]
expected: 62
case 2
in: [1.645,10,1]
expected: 271
case 3
in: [2,1,1]
expected: 4
case 4
in: [1.96,0,0.5]
expected: 0
case 5
in: [1.96,2,0]
expected: 0
Starter codePython
import math
def required_sample_size_mean(z_crit, sigma, margin):
# Your code here
pass5 test cases · run your code against them in the editor