Colormap

The meteorology section of a newspaper assigns a color to each zone of the map of Catalonia depending on its temperature. Now, only winter temperatures are considered and the color is assigned with the following rules:

  • Below 0⁰: white

  • From 0⁰ (included) to 5⁰ (excluded): violet

  • From 5⁰ (included) to 10⁰ (excluded): dark blue

  • From 10⁰ (included) to 15⁰C (excluded): sky blue

  • Greater than or equal to 15⁰: green

Write the function colormap() that takes a temperature (float), and returns a string with the corresponding color.

Save this function into a file named colormap.py.

See the following examples:

>>> colormap(1.2)
'violet'
>>> colormap(5.0)
'dark blue'
>>> colormap(12.5)
'sky blue'
>>> colormap(10.0)
'sky blue'
>>> colormap(15.0)
'green'
>>> colormap(0.0)
'violet'
>>> colormap(-3.5)
'white'
>>> colormap(-3)
'white'
>>> colormap(-0.2)
'white'



Note

More tests are provided in the test-colormap.txt file.

Solution

A solution is provided in the colormap.py file.