import math
def z_stat_proportion(p_hat, p0, n):
se = math.sqrt(p0 * (1 - p0) / n)
return (p_hat - p0) / se
# Testing whether a coin is fair: H0: p = 0.5
p_hat = 0.58 # observed proportion of heads in 100 flips
p0 = 0.5
n = 100
z = z_stat_proportion(p_hat, p0, n)
print("Test statistic z =", round(z, 3))