Lab 9
Dictionary of Colors
Submit by the end of lab

Overview

This lab involves studying the use of a dictionary that looks up the Red, Green, Blue (RGB) model for a given color.

Using lab zip folder

Download the zip folder for lab 9. Unzip it and study the code in colors.py.

Questions

For the following, either answer the question or provide the requested code:

  1. Load colors.py. After you run the module, this Python script creates the global variable color_table. This variable refers to a dictionary consisiting of strings as keys and lists of integers as values. To see this, try these expressions:
    • color_table["BLUE"]
    • color_table["PURPLE"]
    • color_table["GOLDENROD"]
    • color_table["GOLDENROD"]['r']
    Note that the dictionary of integers indicates the respective amounts of red, green and blue for each corresponding color. Now, write an expression that just shows the amount of blue for the color chartreuse.
  2. Run this statement in the interactive shell: show_color("plum"). Explain what happens. Include what functions are called.
  3. Determine the quantity of red, green and blue that defines the color plum.
  4. How many different colors can show_color display? How do you know?
  5. Study the file colors.py and explain how a dictionary is used to look up the red, green and blue components for a color.
  6. Write an interactive function called demo_color. This function should not take any arguments. Instead it asks the user to input a color (e.g. teal). It should print the quantity of red, green and blue to the console. Then, it should display a sample of the color in a browser (like show_color).
  7. Try the following function invocation in the shell: render_color_code({'r': 250, 'g': 200, 'b': 0 }). Try it with other values. What does this function do?
  8. Write a function called demo_blend. This function should take two arguments: two strings each indicating a valid color. It should look up both of their RGB components, average them and print the averages. Then, using the render_color_code function, it should display a sample of the blended color in the browser.

Deliverable

Create a text file called lab9.txt that contains your answers and requested functions.

At the top of the lab, provide a statement of your experience with the lab and whether you worked with others.

Submit your lab9.txt file to D2L.

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.

Labs submitted late are subject to a half point penalty.