We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Python
  3. Introduction
  4. Write a function
  5. Discussions

Write a function

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • nayanbhiwapurkar
    3 years ago+ 6 comments

    Method 1

    def is_leap(year):
    	return year % 4 == 0 and (year % 400 == 0 or year % 100 != 0)
    

    Method 2

    def is_leap(y):
        return (y%400==0) or (y%100!=0 and y%4==0)
    

    Method 3

    def is_leap(year):
        leap = False
        
        if (year % 4 == 0):
            leap = True
            if (year % 100 == 0):
                leap = False
    	if (year % 400 == 0):
                    leap = True
        return leap
    
    17|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature