Last active
November 6, 2019 15:27
-
-
Save gaspart/1f3868360a9c5ddd20e7c378a7dbcf3d to your computer and use it in GitHub Desktop.
the result of throwing two dice for a sufficient number of times will approach their probability
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
from random import randint | |
from matplotlib import pyplot as plt | |
run = 0 | |
R2=0 | |
R3=0 | |
R4=0 | |
R5=0 | |
R6=0 | |
R7=0 | |
R8=0 | |
R9=0 | |
R10=0 | |
R11=0 | |
R12=0 | |
while run < 1000001: | |
dado1 = randint(1,6) | |
dado2 = randint(1,6) | |
Risultato = dado1 + dado2 | |
if Risultato == 2: | |
R2 += 1 | |
if Risultato == 3: | |
R3 += 1 | |
if Risultato == 4: | |
R4 += 1 | |
if Risultato == 5: | |
R5 += 1 | |
if Risultato == 6: | |
R6 += 1 | |
if Risultato == 7: | |
R7 += 1 | |
if Risultato == 8: | |
R8 += 1 | |
if Risultato == 9: | |
R9 += 1 | |
if Risultato == 10: | |
R10 += 1 | |
if Risultato == 11: | |
R11 += 1 | |
if Risultato == 12: | |
R12 += 1 | |
run += 1 | |
print(R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12, sep=' ') | |
plt.plot([R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment