You are given an enum called Direction that represents different directions: North, South, East, and West. You need to write a function called is_opposite that takes two Direction enum values as input and returns True if they are opposite directions (i.e., North/South or East/West) and False otherwise. However, the catch is that you cannot compare the enum values using their integer values or their string names. Instead, it would be best to use the identity comparison (is, is not) to compare the two enum values.
ENUM
Opposite direction
Report a typo
Sample Input 1:
North, SouthSample Output 1:
TrueWrite a program in Python 3
from enum import Enum
class Direction(Enum):
North = 1
South = 2
East = 3
West = 4
def is_opposite(dir1: Direction, dir2: Direction) -> bool:
pass
dir1, dir2 = input().split(", ")
print(is_opposite(Direction[dir1], Direction[dir2]))
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.