lab08 : 2D Lists and Nested for Loops

num ready? description assigned due
lab08 true 2D Lists and Nested for Loops Thu 05/10 03:30PM Wed 05/30 05:00PM

Accepted LATE through June 2nd 11:59pm, without penalty; after that, will be recorded as a zero. No exceptions; an extension has already been given.

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.

Instructions

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):

You will complete the portions in the starter code by doing the following:

  1. Create a directory called ~/cs8/lab08 (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 lab08.py and lab08_tests.py in that cs8/lab08 directory.
  4. Have some paper and a pen/pencil handy. Visualizing the 2D list and screen can help formulate your algorithms before writing the actual code.
  5. ONE AT A TIME, copy the function definitions from the starter code, and the tests that go along with those functions, and get the tests to pass.
    • By one a a time, what I mean is, at your first step, copy ONLY the first function definition from the starter code lab08.py and copy only the import statements and test cases from lab08_tests.py that go with that function definition.
    • Then, before you move on to the next function definition and its tests, get all of the tests from the one you just copied to pass.
    • Then, and only then, copy the next function definition and its tests into your files.
    • Repeat this until you have ALL of the function definitions and their tests, and all of them pass.
    • Since this lab is dealing with 2D lists, it may be hard to visualize your functions’ behavior while inspecting the 2D lists in its list-of-lists form. Consider debugging and verifying small cases by printing the 2D list and manually checking your functionality before running the pytests. You should write these tests in the if __name__=="__main__": condition in lab08.py file. This code will not be executed when importing lab08.py into other python files.

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

A few notes about creating the screen

********************
********************
********************
********************
********************
********************
********************
********************
********************
********************

A few notes about the fill_rect and draw_rect functions

********************
*               ****
*               ****
*               ****
*               ****
*               ****
*               ****
*               ****
*               ****
********************
********************
*               ****
* ************* ****
* ************* ****
* ************* ****
* ************* ****
* ************* ****
* ************* ****
*               ****
********************
********************
*               ****
********************
********************
********************
********************
********************
********************
********************
********************
********************
* ******************
* ******************
* ******************
* ******************
* ******************
* ******************
* ******************
* ******************
********************

A few notes about the draw_line function

This screen of pixels represented as a 2D list is different from a traditional cartesian coordinate system. In a traditional system, the y value (row) increases as you move “up” the screen, while in this system, the y value for the row increases as you move down the screen.

However, the point-slope equation that you learned in high school math still applies.

As a reminder, the point-slope equation is , where is the slope of the line between two points.

The draw_line function’s parameter has the row1, col1 value of one pixel on the screen and row2 and col2 value of the other pixel on the screen.

  ******************
**  ****************
****  **************
******  ************
********  **********
**********  ********
************  ******
**************  ****
****************  **
******************  

******************************
*************************    *
******************       *****
************      ************
*****       ******************
*    *************************
******************************
******************************
******************************
******************************
********************
* ******************
********************
********************
********************
********************
********************
********************
********************
********************

Upload lab08.py and lab08_tests.py to Gradescope.

Once you’re done with writing your functions, navigate to the Lab assignment lab08 on Gradescope and upload your lab08.py> and lab08_tests.py 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 lab08.