University of Arizona, Department of Computer Science

CSc 120: Classes: Color

Expected Behavior

The class Color represents a color using the RGB color model. (See the following reference for information on the RGB color model: https://en.wikipedia.org/wiki/RGB_color_model .) The class Color stores the red, green, and blue components of a color as integers. Each integer is in the range of range of 0 to 255 (inclusive).

Write a Python class Color that meets the following requirements:

Attributes:

Methods:

Examples

  1. color1 = Color(50,100,140)
    color1.get_rgb()


    Result: (50, 100, 140)

  2. color1 = Color(50,100,140)
    str(color1)


    Result: "Color(50,100,140)"

  3. color1 = Color(135,50,140)
    color1.remove_red()
    str(color1)


    Result: "Color(0,50,140)"

  4. color1 = Color(50,100,140)
    color2 = Color(135,50,140)
    color1 == color2


    Result: False

  5. color1 = Color(65,100,180)
    color2 = Color(65,100,180)
    color1 == color2


    Result: True

  6. color1 = Color(255,255,255)
    color1.remove_red()
    str(color1)


    Result: "Color(0,255,255)"

  7. color1 = Color(255,255,255)
    color1.remove_red()
    color1.get_rgb()


    Result: (0,255,255)

  8. color1 = Color(50,100,140)
    color1.get_rgb()[2]


    Result: 140