#diceroll.py #Simulate the rolling of two dice using the random #number generator. from random import * # Minimum number of sides on a die MIN_SIDES = 4 # Our very own main routine for a top-down design. # This is not a standard function in Python. def main() : print "Dice roll simulation." numSides = int( raw_input( "How many sides should the die have? " ) ) if numSides < MIN_SIDES : numSides = MIN_SIDES value = rollDice( numSides ) print "You rolled a", value # Simulate the rollowing of two nSided dice. def rollDice( nSides ) : die1 = randint( 1, nSides + 1 ) die2 = randint( 1, nSides + 1 ) return die1 + die2 # Call the main routine which we difined as the first # function in the file. main()