Lab 3
Using a class and defining a method in a class
Submit after the end of the lab session

Overview

For this lab, you will continue practice of using a predefined class and modifying it.

Instructions and questions

  1. Download the zip folder for the lab.
  2. Study the code in files demo.py and color.py.
  3. Run the demonstration functions in demo.py. Explain to yourself what they do and how they work.
  4. What are the instance variables for the Color class?
  5. Does the Color class have any class variables? A class variable is a variable that is assigned a value outside of the methods (but within the class). It persists as long as the class is loaded in computer memory.

Code writing

  1. Write a function called show_color that takes a string as an argument that represents a common color. It should display that color. It doesn't return any value.
  2. Write a function called show_colors that takes a list of strings, each representing common colors (i.e. those in the color table). It should serially display each of the colors. Note, you'll need to close the window frame before the next one appears.
  3. Add a new method called complement to the Color class. This method should create a new Color object whose red, green and blue components are 255 - the color component of the self object. For example, if the self component of red is 100, the color component of the new object is 155 (i.e. 255 - 100).
  4. Test your new component method by creating a new method called show_complement_colors. It works like show_colors, except it serially displays all of the complement colors in the list.

Deliverable

Create a text (preferred) or pdf file that contains the following:

  1. A statement that summarizes your completion of the lab. As appropriate, the statement should include the following:
    • Who you worked with on the lab
    • Any difficulties you encountered
    • How you tested it (output can be provided at the end of your file)
  2. Your clearly labeled answers to explanations and questions
  3. A summary of the files included in the zip folder
  4. Demonstrations that show that your code works

Put your files in a folder, zip it and submit it under Lab 3 on D2L. Check that your submitted zip file is complete.

Grading

Your lab submission will be graded using the following rubric:

  • + .5 --- Your submission is clearly formatted.
  • + .5 --- Your submission includes a summary statement and includes how you collaborated.
  • + .5 / 1.0 --- You submitted most of the lab (0.5) or you submitted all of the lab (1.0).
  • + .5 --- Your lab submission is generally correct.