Created
June 16, 2022 07:42
-
-
Save DRMacIver/d83a439a3e5627d7f90a5034c9c1eac1 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
#!/usr/bin/env python | |
from datetime import date | |
import calendar | |
if __name__ == '__main__': | |
today = date.today() | |
if today.day == 1: | |
day = "1st" | |
elif today.day == 2: | |
day = "2nd" | |
elif today.day == 3: | |
day = "3rd" | |
else: | |
day = f"{today.day}th" | |
# Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the years 1600 and 2000 are.[14] | |
if today.year % 4 == 0: | |
is_leap_year = (today.year % 100 != 0) or (today.year % 400 == 0) | |
else: | |
is_leap_year = False | |
print(f"It is {calendar.day_name[today.weekday()]}, {day} of {calendar.month_name[today.month]}, {today.year}.") | |
if is_leap_year: | |
print("It is a leap year.") | |
else: | |
print("It is not a leap year.") | |
start_of_year = date(today.year, 1, 1) | |
start_of_next_year = date(today.year + 1, 1, 1) | |
day_of_year = (today - start_of_year).days + 1 | |
days_left_in_year = (start_of_next_year - today).days | |
print(f"Today is day {day_of_year} of {today.year}") | |
if days_left_in_year == 1: | |
print(f"Today is the last day of {today.year}") | |
else: | |
print(f"There are {days_left_in_year} days left in {today.year} (counting today)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment