Dice
With the random module you can create programs that appear to be unpredicable, like the rolling of dice.
Details
Create a python program that simulates rolling a pair of six-sided dice. The program should prompt the user to enter the number of rolls, print all of the rolls, and the average of the rolls.
-
Inside of a loop, use the random
module's
randrange
function to repeately generate two integers in between 1 and 6. - Use an accumulator to compute the sum of all of the dice rolls.
- After the loop, use the accumulated sum to compute the average.
Example
Enter the number of rolls: 3 2 2 1 2 4 1 The average roll is 4.0
Challenge
What's the difference between using two six-sided dice and three four-sided dice? They both have a maximum value of 12, but do they have different average values? Write program that simulates rolling both kinds of dice and prints the average of both. Be sure to "roll" the dice many times to get an accurate average.