htrantk 0 Newbie Poster

The goal of this project is to use if-else statements, anydbm, and turtle graphics in a
Python program to make a database of colors. If the program is called colordb.py, then
a session at the command prompt $ happens as follows:

$ python colordb.py
hit enter to give a color code
or else type the name of a color :
-> give a triplet (*,*,*), * in 0..255 : (255,255,0)
-> give a name for the color (255, 255, 0) : yellow
-> added (yellow,16776960) to the color database
hit enter to exit

After the user enters the code (255,255,0), a turtle window comes up with its background
color corresponding to the given color code. After yellow is entered, the title of the turtle
window changes into yellow. Note: 255 × 2562 + 255 × 256 + 0 = 16776960.
Another result of this session is that a file colors.dbm was made with anydbm. This
file stores the map between color codes and color names. The color is stored twice: once
with as key the name of the color and as value the code of the color; and once with as key
the code of the color and as value the name of the color. Two followup sessions are
$ python colordb.py
hit enter to give a color code
or else type the name of a color : yellow
hit enter to exit
$ python colordb.py
hit enter to give a color code
or else type the name of a color :
-> give a triplet (*,*,*), * in 0..255 : (255,255,0)
hit enter to exit
In both followup sessions, a turtle window pops up with title yellow and background color
with code (255,255,0). In the first session, the code (255,255,0) is computed from
16776960. In the second session, the code (255,255,0) is transformed into 16776960.
To add a new color to the database, we could start entering the code (as done above
with (255,255,0)) or start entering the name of the color. For example:

$ python colordb.py
hit enter to give a color code
or else type the name of a color : blue
-> "blue" is not in the color database
-> give a triplet (*,*,*), * in 0..255, for the color "blue" : (0,0,255)
-> added (blue,255) to the color database
hit enter to exit

Also in this case, a turtle window pops up after the user enters the code (0,0,255) with
background color corresponding to the code and with window title equal to the given name.
For this project we use the integer color codes, via triplets of integer numbers between 0
and 255 (we have exactly 2563 = 16, 777, 216 different colors to choose from). Some useful
turtle methods are illustrated below:

>>> import turtle
>>> turtle.colormode(255) # switch to 0..255 ranges in triplets
>>> turtle.bgcolor((255,0,0)) # set the background color of screen
>>> turtle.title("red") # red appears in title bar of window

As to anydbm, the types of keys and values are always strings, so observe the proper
use of the str() and eval() commands. To every color triplet (c0, c1, c2) corresponds a
unique number n = c02562 + c1256 + c2 and for every number in the range 0 . . . 16777215,
there is a unique color triplet.