@justinholman/

CoinFlipSim-02

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# import modules
import numpy as np
import random

# initiate variables
simcount = 0
heads = 0
percent_heads = []  # this tells python we want a list

# Simulate flipping a coin repeatedly
for i in range(100) :
  simcount += 1
  rand1 = random.random()
  if rand1 >= 0.5 :
    heads += 1
  pct_heads = round(heads/simcount,4)
  percent_heads.append(pct_heads) # here's where we update the list variable
  #print(pct_heads)

print(percent_heads)
print("sim complete")

# this program runs the simulation and saves output to a list variable