Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Created September 29, 2020 18:40
Show Gist options
  • Save SaraM92/874c9f02212c4d3bf3ab43fee34da268 to your computer and use it in GitHub Desktop.
Save SaraM92/874c9f02212c4d3bf3ab43fee34da268 to your computer and use it in GitHub Desktop.
#Import libraries to help simulate experimental probabilities
import random
from collections import Counter
#A function to genrate randome experiments
def gen(x):
expResults = []
for i in range(x):
expResults.append(random.randint(1,6))
return expResults
#An experiment with 100 events
event1 = dict(Counter(gen(100)))
for k,v in sorted(event1.items()):
print("probability of", k, "is",v/100)
print("------------------------------")
#An experiment with 1000 events
event2 = dict(Counter(gen(1000)))
for k,v in sorted(event2.items()):
print("probability of", k, "is",v/1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment