gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
How to determine consist year 29 february or not in Python?
- User
How to determine consist year 29 february or not in Python?
- Assistant
To determine whether a year is a leap year or not, you can use the calendar module in Python. Here's an example:
pythonimport calendar def is_leap_year(year): return calendar.isleap(year) year = 2020 is_leap = is_leap_year(year) if is_leap: print(f"{year} is a leap year.") else: print(f"{year} is not a leap year.")In the above code, the
isleap()function from thecalendarmodule is used to check if the givenyearis a leap year or not. If the year is a leap year, it returnsTrue; otherwise, it returnsFalse.