Leap Year In Python

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 35:- Leap Year In Python

In Python, you can determine if a given year is a leap year or not using conditional statements. A leap year is a year that is exactly divisible by 4, except for years that are divisible by 100. However, years that are divisible by 400 are considered leap years. Here's how you can check if a year is a leap year:

pythonCopy code

def is_leap_year(year):    if year % 4 == 0:        if year % 100 == 0:            if year % 400 == 0:                return True            else:                return False        else:            return True    else:        return False # Example usage: year = 2024 if is_leap_year(year):    print(f"{year} is a leap year.") else:    print(f"{year} is not a leap year.")

In this example, the is_leap_year() function takes a year as input and uses nested if statements to check the conditions for leap years. If the year is exactly divisible by 4, it enters the first level of the if statement. If it is divisible by 100, it checks if it is also divisible by 400 to determine if it is a leap year. If all conditions are met, the function returns True, indicating that the year is a leap year. Otherwise, it returns False.

You can call the is_leap_year() function with different years to check if they are leap years or not. The function will return True for leap years and False for non-leap years.

5. Flow Control

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?