Created
October 12, 2024 23:39
-
-
Save omamkaz/8055e1c474bfca12e5b6826003e7b16a to your computer and use it in GitHub Desktop.
simple Python script that displays a "Good Morning," "Good Afternoon," or "Good Evening" message based on the current time
This file contains hidden or 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
class Greet: | |
class Types(StrEnum): | |
morning: str = "morning" | |
afternoon: str = "afternoon" | |
evening: str = "evening" | |
@staticmethod | |
def morning(hour: int) -> bool: | |
return 5 <= hour < 12 | |
@staticmethod | |
def afternoon(hour: int) -> bool: | |
return 12 <= hour < 18 | |
@staticmethod | |
def evening(hour: int) -> bool: | |
return hour >= 6 | |
@classmethod | |
def greet(cls, hour: int) -> bool: | |
if cls.morning(hour): | |
return cls.Types.morning | |
if cls.afternoon(hour): | |
return cls.Types.afternoon | |
return cls.Types.evening | |
if __name__ == "__main__": | |
from datetime import datetime | |
cur_hour: int = datetime.now().hour | |
greet = Greet.greet(cur_hour) | |
print(f"Good {greet.value.title()} :)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment