Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python program to check leap year or not?

# Python program to check if year is a leap year or not
year = 2004
# To get year (integer input) from the user
# year = int(input("Enter a year: "))
# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
    print("{0} is a leap year".format(year))
# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
    print("{0} is a leap year".format(year))
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
    print("{0} is not a leap year".format(year))
Comment

python Program to check if a given year is leap year

# Python program to check leap year or not
def checkYear(year):
    if (year % 4) == 0:
        if (year % 100) == 0:
            if (year % 400) == 0:
                return True
            else:
                return False
        else:
             return True
    else:
        return False
 
# Driver Code
year = 2000
if(checkYear(year)):
    print("Leap Year")
else:
    print("Not a Leap Year")
     
Comment

leap year python

y = int(input())
if (y % 400 == 0) or (y % 100 != 0 and y %4 == 0):
    print(y,"is leap year.")
else:
    print(y,"isn't leap year.")
Comment

check if year is leap python

# Use calendar.isleap(year)
# https://docs.python.org/3/library/calendar.html#calendar.isleap has more information

import calendar
is_leap = calendar.isleap(2100) # returns False
Comment

how to calculate leap year in python with function

#Leap year calculator
print('Leap year calculator')
print('>>>')
#=======================================
def is_leap_year(year):
  if (year % 400 == 0) and (year % 100 == 0):
    print(str(year) + " is a leap year".format(year))
    return True
  elif (year % 4 ==0) and (year % 100 == 0):
    print(str(year) + " is a leap year".format(year))
    return True
  else:
    print(str(year) + " is not leap year")
    return False
#=======================================
#input here
#            V  (insert year in ())
is_leap_year(2000)
#=========================================================
Comment

PREVIOUS NEXT
Code Example
Python :: random picker in python 
Python :: generate n different random numbers python 
Python :: how to remove rows with certain values pandas 
Python :: python capture desktop as video source 
Python :: for each loop python 3 
Python :: read_table python 
Python :: assign python 
Python :: open and read a file in python 
Python :: python ssl module is not available 
Python :: how to reset index after dropping rows pandas 
Python :: python get item from queue 
Python :: Python Removing Directory or File 
Python :: create and populate dictionary python 
Python :: reverse an array python 
Python :: django group by 
Python :: how to get input python 
Python :: python ternary 
Python :: randomforestregressor in sklearn 
Python :: python how to import library absoluth path 
Python :: python exit for loop 
Python :: # invert a dictionary 
Python :: how to take input complex number in python 
Python :: matplotlib custom legend 
Python :: pandas groupby apply list 
Python :: rotate 90 degrees clockwise counter python 
Python :: django custom save method 
Python :: creating data frame in python with for loop 
Python :: python recurrent timer 
Python :: extract data from json file python 
Python :: np random seed 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =