Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!

Start the ChallengeA tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcast**OBJECTIVES**

- Review Plotting Functions
- Review Combination Numbers
- Review Binomial Distribution
- Review Normal Distribution
- Review center and spread of distribution

In [ ]:

```
#import libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
```

In [ ]:

```
#define a function
def f(x): return x**2
```

In [ ]:

```
#plot the function
x = np.linspace(-3, 3, 1000)
plt.plot(x, f(x))
```

Out[ ]:

In [ ]:

```
#square roots, trigonometric, exponential, and subplots
fig, ax = plt.subplots(1, 3, figsize = (16, 4))
def s(x): return np.sqrt(x)
def sin(x): return np.sin(x)
def e(x): return np.e**x
ax[0].plot(x, s(x))
ax[1].plot(x, sin(x))
ax[2].plot(x, e(x));
```

In [ ]:

```
#tables of values
functions = pd.DataFrame({'x': x, 's(x)': s(x), 'sin(x)': sin(x), 'e^x': e(x)})
functions.head()
```

Out[ ]:

In mathematics, a combination is a selection of items from a collection, such that the order of selection does not matter (unlike permutations). For example, given three fruits, say an apple, an orange and a pear, there are three combinations of two that can be drawn from this set: an apple and a pear; an apple and an orange; or a pear and an orange. More formally, a k-combination of a set S is a subset of k distinct elements of S. If the set has n elements, the number of k-combinations is equal to the binomial coefficient

$\displaystyle {\binom {n}{k}}={\frac {n(n-1)\dotsb (n-k+1)}{k(k-1)\dotsb 1}},$

which can be written using factorials as $\frac {n!}{k!(n-k)!}$ whenever $\displaystyle k\leq n$, and which is zero when $k>n$. The set of all k-combinations of a set S is often denoted by $\binom {S}{k}$.

In [ ]:

```
#import combination function
from scipy.special import comb
```

In [ ]:

```
#3 choose 2
comb(3, 2)
```

Out[ ]:

In [ ]:

```
#3 choose 0, 1, 2, 3
[comb(3, i) for i in [0, 1, 2, 3]]
```

Out[ ]:

In [ ]:

```
#build the triangle
for i in range(10):
print([comb(i, j) for j in range(i + 1)])
```

In [ ]:

```
#row 7
row_seven = [1.0, 7.0, 21.0, 35.0, 35.0, 21.0, 7.0, 1.0]
```

In [ ]:

```
#plot the row
plt.bar(range(8), row_seven)
```

Out[ ]:

In [ ]:

```
#total
sum(row_seven)
```

Out[ ]:

In [ ]:

```
#probability of 3 successes
35/128
```

Out[ ]:

In [ ]:

```
#binomial distribution
#import
import scipy.stats as stats
b = stats.binom(7, .5)
b.pmf(3)
```

Out[ ]:

In [ ]:

```
#example
plt.bar(range(8), b.pmf(range(8)))
```

Out[ ]: