Created
March 7, 2020 12:20
-
-
Save luizomf/75182fe0251ad38cdb3f354e226c0263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum, auto | |
class Directions(Enum): | |
right = auto() | |
left = auto() | |
up = auto() | |
down = auto() | |
def move(direction): | |
if not isinstance(direction, Directions): | |
raise ValueError('Cannot move in this direction') | |
return f'Moving {direction.name}' | |
if __name__ == "__main__": | |
print(move(Directions.right)) | |
print(move(Directions.left)) | |
print(move(Directions.up)) | |
print(move(Directions.down)) | |
print() | |
for direction in Directions: | |
print(direction, direction.value, direction.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment