lab06 : String formatting, random, and file IO

num ready? description assigned due
lab06 true String formatting, random, and file IO Tue 02/26 01:00PM Mon 03/04 11:59PM

This lab is due on Monday, March 4th by 11:59 PM

In this lab, you’ll get more practice with:

This lab may be done solo, or in pairs.

Before you begin working on the lab, please decide if you will work solo or with a partner.

A reminder about working with a pair programming partner:

Once you and your partner are in agreement, choose an initial driver and navigator, and have the driver log into their account.


In this lab, you will need to create two files:

Starter code is provided for you and are located at (you may need to refresh the page if the links do not load immediately):

  1. Create a directory called ~/cs8/lab06 (using the mkdir command) and cd into that directory.
  2. Use idle3 (you might try idle3 & if you want to be able to type commands on your terminal window after IDLE opens).
  3. Use “New File” to create empty files called and in that ~/cs8/lab06 directory.
  4. Download input1.txt and input2.txt in that ~/cs8/lab06 directory. These are used when running pytest on

You are encouraged to try submitting to Gradescope periodically for several reasons:

Some notes about printing the dice distribution

This portion of the lab will be manually graded by our TAs and not autograded by gradescope (though your submission must include the rollDice, rollDistribution and printDistribution functions in

An example printDistribution function will appear as follows:

Distribution of dice rolls

 2:     7 (  2.8%)  *******
 3:    14 (  5.6%)  **************
 4:    29 ( 11.6%)  *****************************
 5:    26 ( 10.4%)  **************************
 6:    34 ( 13.6%)  **********************************
 7:    41 ( 16.4%)  *****************************************
 8:    30 ( 12.0%)  ******************************
 9:    23 (  9.2%)  ***********************
10:    23 (  9.2%)  ***********************
11:    16 (  6.4%)  ****************
12:     7 (  2.8%)  *******
250 rolls

>>> printDistribution(rollDistribution(250))

Some notes about the File I/O functions

This portion of the lab will be autograded by gradescope. Two input files are provided for you to test your functionality. One additional input file is not provided and will be tested with your submission on Gradescope.

Note that all words are separated by a whitespace character, and a word contains only alpha-numeric characters that does not include punctuation characters. For simplicity, you may assume the text only contains the ,.!?; punctuation characters. Your code will need to split and strip the text file string appropriately.

Upload and to Gradescope.

Once you’re done with writing your functions, navigate to the Lab assignment “Lab06” on Gradescope and upload your and files. Remember to add your partner to Groups Members for this submission on Gradescope if applicable. At this point, if you worked in a pair, it is a good idea for both partners to log into Gradescope and see if you can see the uploaded files for Lab06.