# Programmer: Sriram Pemmaraju # Date: 2/29/2012 # This program rolls a pair of n-sided dice a million times and reports the frequency of each outcome. # An outcome is the sum of the two numbers that appear on the top face of the two dice. Note that for # a pair of n-sided dice, the outcomes will be in the range 2..2n. import random n = int(raw_input("Please type the number of sides in your dice.")) L = [0]*(2*n+1) # Creates a list of length 2*n+1 with all elements of the # list initialized to 0 for i in range(1000000): # Roll the two n-sided dice and record the outcome outcome = random.randint(1, n) + random.randint(1, n) # L[outcome] stores the number of times outcome has appeared # So this element in the list needs to be incremented L[outcome] = L[outcome] + 1 #Report the contents of slots 2, 3, ... print L[2:]