-
-
Save glyph/ad25a9e8d93bb9f7ac15a947cbf53a5d 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 typing import Literal | |
AMPM = Literal["AM", "PM"] | |
def ampmify(hour: int, ampm: AMPM) -> int: | |
if hour == 12: | |
if ampm == "AM": | |
return 0 | |
else: | |
return 12 | |
elif ampm == "PM": | |
return hour + 12 | |
else: | |
return hour | |
def addampm(hour: int) -> tuple[int, AMPM]: | |
if hour == 0: | |
return (12, "AM") | |
elif hour == 12: | |
return (12, "PM") | |
elif hour > 12: | |
return (hour - 12, "PM") | |
else: | |
return (hour, "AM") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment