Get your own Python server Result Size: 625 x 565
x
 
import scipy.stats as stats
import math
# Specify sample mean (x_bar), sample standard deviation (s), sample size (n) and confidence level
x_bar = 62.1
s = 13.46
n = 30
confidence_level = 0.95
# Calculate alpha, degrees of freedom (df), the critical t-value, and the margin of error
alpha = (1-confidence_level)
df = n - 1
standard_error = s/math.sqrt(n)
critical_t = stats.t.ppf(1-alpha/2, df)
margin_of_error = critical_t * standard_error
# Calculate the lower and upper bound of the confidence interval
lower_bound = x_bar - margin_of_error
upper_bound = x_bar + margin_of_error
# Print the results
print("Critical t-value: {:.3f}".format(critical_t))
print("Margin of Error: {:.3f}".format(margin_of_error))
print("Confidence Interval: [{:.3f},{:.3f}]".format(lower_bound,upper_bound))
print("The {:.1%} confidence interval for the population mean is:".format(confidence_level))
print("between {:.3f} and {:.3f}".format(lower_bound,upper_bound))
Critical Z-value: 2.045
Margin of Error: 5.026
Confidence Interval: [57.074,67.126]
The 95.0% confidence interval for the population mean is:
between 57.074 and 67.126