Programming‎ > ‎Mini-Projects‎ > ‎

03 Dice


Using lists, write a program that will roll a specified number of dice and add the rolls. The program must do this a specfied number of times and print a horizontal histogram showing the distribution of scores. The base of the histogram rows must have the score (e.g. 3, 4, 5, etc.). Each row of the histogram must be scaled so that the length of the maximum bar is 50 stars. The number of times that score was rolled must be printed at the end of the bar. For example, the output should look like this:
 
 
>>> 
number of dice? 2
number of rolls? 200

2 *************** 10
3 ************ 8
4 ************* 9
5 *********************************** 24
6 *************************************** 27
7 *************************************************** 35
8 ************************************************* 34
9 ************************** 18
10 **************************** 19
11 ****************** 12
12 ****** 4

Type 'done' to exit: 

number of dice? 3
number of rolls? 2000


3 *** 12
4 ***** 24
5 ********** 48
6 ******************* 98
7 ********************** 116
8 ************************************** 198
9 ***************************************** 215
10 ********************************************** 240
11 *************************************************** 265
12 ********************************************** 242
13 *************************************** 203
14 *************************** 141
15 ******************* 96
16 ************* 65
17 ******* 35
18 * 2


Type 'done' to exit: done
>>> 
 
 The random module will be useful for generating random numbers. Your code must comply with the style tips we discussed in class.