Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
46 views
ubuntu2004
Kernel: Python 3 (system-wide)
import numpy as np
np.random.randint(0,2,size=10)
array([0, 0, 0, 0, 0, 1, 1, 0, 0, 1])

we use this to generate a random list of a coin toss.

def ten_flips(): flips = np.random.randint(0,2,size=10) head = 0 for coin in flips: if np.sum(flips) >= 5: head = head + 1 return head

We have this set up so that when the coin is flipped, if it is greater than or equal to 5, it will be added onto the counter.

ten_flips()
0
(sum([ten_flips() for i in range(100)])/100)
0.61

This would mean that the probability of getting at least 5 heads is roughly 61%