Chapters
Python114 chapters

Exercises

Enums

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Replace the loose strings with an enum, and print the value of NORTH.

Python
# define Direction with NORTH and SOUTH
print(Direction.NORTH.value)
Exercise 2

Print the names of every member, in order.

Python
from enum import Enum

class Status(Enum):
    PENDING = 1
    ACTIVE = 2
    DONE = 3

# print ['PENDING', 'ACTIVE', 'DONE']
Exercise 3

Make the members compare equal to their string values.

Python
from enum import Enum

class Mode(Enum):
    FAST = "fast"

print(Mode.FAST == "fast")