A z test for a mean

A company claims its batteries last μ₀ hours on average. You test a sample and want to know whether the claim survives.

What to build

A program that runs a two-sided z test at the 5% level.

Requirements

  • Print standard error S (3 decimal places) and z Z (2 decimal places).
  • Then print reject H0 when the absolute value of z is over 1.96, otherwise keep H0.

Input

One line: μ₀, the sample mean, the sample standard deviation and n.

Output

Three lines.

Constraints

2 ≤ n ≤ 10⁶; the standard deviation is over 0.

Example

Input:

100 103 10 25

Output:

standard error 2.000
z 1.50
keep H0

Why it works

Under H₀ the sample mean is roughly normal around μ₀ with standard deviation s ÷ √n, so z measures the distance in standard errors, and only 5% of z values fall beyond ±1.96.

Examples

Example 1 · Input
100 103 10 25
Expected output
standard error 2.000
z 1.50
keep H0
Example 2 · Input
50 48 4 64
Expected output
standard error 0.500
z -4.00
reject H0

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

The standard error is sd ÷ √n.

Hint 2

z = (sample mean − μ₀) ÷ standard error; reject when the size of z is over 1.96.

Solution

Show one correct solution (try it yourself first)
mu0, mean, sd, n = map(float, input().split())
se = sd / n ** 0.5
z = (mean - mu0) / se
print(f"standard error {se:.3f}")
print(f"z {z:.2f}")
print("reject H0" if abs(z) > 1.96 else "keep H0")

Lesson: Hypothesis testing and p-values →