Last active
April 17, 2018 19:48
-
-
Save misterhay/f5617baf8f7b564cd3e0e7145a4f6a90 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
numberOfRolls = 10 | |
numberOfSides = 6 | |
from random import randint # a module for random integers | |
resultsList = [] # create an empty list | |
for x in range(0,numberOfRolls): # loop through this a number of times | |
number1 = randint(1, numberOfSides) # pick a number between 1 and 6 | |
number2 = randint(1, numberOfSides) # pick another number between 1 and 6 | |
total = number1 + number2 # add those two values | |
#print(total) | |
resultsList += [total] # append the sum to the resultsList | |
from collections import Counter | |
counts = Counter(resultsList) # count how many times we got each sum | |
import matplotlib.pyplot as plot | |
plot.bar(list(counts.keys()),list(counts.values())) # create a bar graph from that count | |
plot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment