Dataclasses, enumerations and types · 13 / 15 Exercise Medium

Next color

Objective

Create a Python program that looks up a member of an enumeration by its name and goes through the enumeration.

Instructions

  • Define class Color(Enum) with RED = 1, GREEN = 2 and BLUE = 3.
  • Read the name of a color and look it up with Color[name]. If it does not exist, Python raises KeyError: show Unknown color.
  • If it exists, show Value: V and, on the next line, Next: NAME, with the member that follows in the enumeration (after BLUE it goes back to RED). Use list(Color) to get the members in order.
Input
GREEN
Output
Value: 2
Next: BLUE

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise