Created
April 19, 2023 20:28
-
-
Save Godwhitelight/1c6ea9c230b4633d72476b7befd96f0f to your computer and use it in GitHub Desktop.
get days in a month in a year python
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
def get_days(month: int, year: int): | |
""" | |
Get the number of days in a month | |
:param month: The month | |
:param year: The year | |
:return: The number of days in the month | |
:Example: | |
>>> get_days(2, 2020) | |
29 | |
>>> get_days(2, 2019) | |
28 | |
>>> get_days(4, 2020) | |
30 | |
""" | |
if month == 2: | |
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0): | |
return 29 | |
return 28 | |
return 30 + (1 - (month % 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment