Created
April 8, 2018 00:43
-
-
Save antonio-catalano/c3b4c954da5a8881c98b0031f4aecbe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' There are ten coins, each blank on one side and numbered on the other side with numbers 1 through 10. | |
All ten coins are tossed and the sum of numbers landing face up is calculated. What is the probability that this sum is at least 45? | |
''' | |
import random | |
def toss_coin (x): | |
coin = random.choice ([0,x]) #a discrete uniform distribution between values of a sequence, in this case 2 values possible. | |
return (coin) | |
count = 0 | |
n = 1000000 | |
for i in range (n): # montecarlo method | |
somma_total = 0 | |
for i in range (1,11): | |
somma_coin = 0 | |
for k in range (1): | |
somma_coin = somma_coin + toss_coin(i) | |
somma_total = somma_total + somma_coin | |
if somma_total >= 45: | |
count += 1 | |
print ('Probability that sum is at least 45 : ', float(count / n)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment