Get part of day (morning, afternoon, evening, night) in Python
#!/usr/bin/env python | |
from sys import stdout | |
def get_part_of_day(hour): | |
return ( | |
"morning" if 5 <= hour <= 11 | |
else | |
"afternoon" if 12 <= hour <= 17 | |
else | |
"evening" if 18 <= hour <= 22 | |
else | |
"night" | |
) | |
# If you want to use current hour: | |
# from datetime import datetime | |
# h = datetime.now().hour | |
# stdout.write('have a good {0}!\n'.format(get_part_of_day(h))) | |
for h in range(0, 24): | |
stdout.write('hour {0} is {1}\n'.format(h, get_part_of_day(h))) |
This comment has been minimized.
This comment has been minimized.
Thank you. |
This comment has been minimized.
This comment has been minimized.
I think the official time to say "evening" in this part of the world is 19:00. Just an opinion. |
This comment has been minimized.
This comment has been minimized.
Then again, this varies a lot it seems: https://en.wikipedia.org/wiki/Evening |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thanks. Usefull!.