Modify a Python program to make unfair dice.
Download fairDice.py (or use the program from the previous module):
Start IPython:
Currently, the dice program you used in the previous module randomly selects numbers with equal probability. Imagine that you now want a certain number to be rolled more often than the others. Examine the fairDice program again. Can you find the line where the random number is chosen?
Try to change the program so that the number 2 is rolled twice as often as the number 3. How would you make the number 2 be rolled three times as often? Do you think you could make the numbers show up with increasing probability? Try to make the number 1 have the lowest probability and the number 6 have the highest probability.
To visualize the results of the rolls, change the histogram variable from False
to True
. Was your attempt at changing the probabilities successful?
You can also check the results of each individual roll by viewing the log file rolls.log.
Don't forget to save the histogram for your web page - you can also save a screenshot of your code! Remember to answer the questions on this page.