Simulating the binomial distribution

We flip a coin 20 times and we get 14 heads: is it a fair coin ? Let’s find this out.

import numpy as np

trials = 10000
flips = (sum(np.random.choice(2, 20)) for _ in range(trials))

i = 0
for f in flips:
    if f >= 14:
        i += 1

if i >= 0.05:
    print("the coin is fair")
else:
    print("something is going on!")
the coin is fair