Solution to: [Day 6: The Central Limit Theorem III](https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-3/problem)

<h1 id="tocheading">Table of Contents</h1>
<div id="toc"></div>

- Table of Contents
- Notes
- Solution
    - Imports
    - Inputs
    - Z Score
    - Format
    - Main


```javascript
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')
```


    <IPython.core.display.Javascript object>


# Notes
This solution uses the following z-score formula:
\begin{equation}
\large
z = \frac
{x - \mu}
{\sigma}
\end{equation}


Because the problem gives us the z-score and asks us to find the bounds, we can solve the formula for x:

\begin{equation}
\large
x = z * \sigma + \mu
\end{equation}


We can assume: 
- mean_sample = mean_population, and 
- sd_sample = sd_population / sqrt(n)

*NOTE*: When extrapolating sample statistics to population statistics, the following are derived from the Central Limit Theorem:
1. mean_sample = mean_population
2. standard error (population) = sd_sample / sqrt(n)
    As the sample increases, means cluster more closely around the mean

# Solution

## Imports


```python
from typing import Tuple
```

## Inputs


```python
def get_input() -> Tuple[int, int, int, float, float]:
	"""Returns input for Day 6: Central Limit Theorem III.

	Returns:
		Tuple[int, int, int, float, float]: num_students, mean, sd, distribution percent, z-score
	"""
	return 100, 500, 80, 0.95, 1.96
```

## Z Score


```python
def calc_std_err(sd: int, n: int) -> float:
	"""Returns standard error of population

	Args:
		sd (int): Standard deviation
		n (int): Sample

	Returns:
		float: Standard error
	"""
	return sd / (n ** (1/2))
```


```python
def calc_val_from_zscore(z_score: float, mean: int, sd: int) -> float:
	"""Returns value associated with the z-score from sample mean & sd.

	Args:
		z_score (float): z-score
		mean (int): sample mean
		sd (int): sample sd

	Returns:
		float: value assocaited with z-score given sample mean & sd
	"""
	return z_score * sd + mean
```

## Format


```python
def print_to_scale(num: int) -> None:
	"""Prints number to 2 decimal point scale

	Args:
		num (int): Number to print
	"""
	print(f"{num :.2f}")
```

## Main


```python
def main():
	num_students, mean, sd, dist_percent, z_score = get_input()
	std_err = calc_std_err(sd, num_students)

	## Bottom bound of dist_percent
	a = calc_val_from_zscore(-z_score, mean, std_err)
	## Top bound of dist_percent
	b = calc_val_from_zscore(z_score, mean, std_err)

	## Print
	print_to_scale(a)
	print_to_scale(b)
```


```python
if __name__ == "__main__":
	main()
```

    484.32
    515.68


ced2e4cee79c23f62773e910334da131474e13e9
ipynb
Jupyter Notebook
statistics/10_days/22_day6thecentrallimittheoremiii.ipynb
jaimiles23/hacker_rank
0580eac82e5d0989afabb5c2e66faf09713f891b
Apache-2.0
statistics/10_days/22_day6thecentrallimittheoremiii.ipynb
jaimiles23/hacker_rank
0580eac82e5d0989afabb5c2e66faf09713f891b
Apache-2.0
statistics/10_days/22_day6thecentrallimittheoremiii.ipynb
jaimiles23/hacker_rank
0580eac82e5d0989afabb5c2e66faf09713f891b
Apache-2.0
2021-09-22T11:06:58.000Z
2022-01-25T09:29:24.000Z
Qwen/Qwen-72B
1. YES
2. YES