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 :: python code to wait 
Python :: python check if string is a float 
Python :: pygame change icon 
Python :: how to check if its later than python 
Python :: random variables python 
Python :: opencv face detection code python webcam 
Python :: managing media in django 
Python :: loading text file delimited by tab into pandas 
Python :: latest django version 
Python :: python convert datetime.timedelta into seconds 
Python :: python launch file 
Python :: powershell to python converter 
Python :: Remove the Unnamed column in pandas 
Python :: print list vertically in python with loop 
Python :: take off character in python string 
Python :: unpack dictionaryp 
Python :: py pause script 
Python :: how to loop over month name in python 
Python :: raw string 
Python :: python dictionary get keys with condition on value 
Python :: python test if string is int 
Python :: how to move your cursor using python 
Python :: run code at the same time python 
Python :: python class tostring 
Python :: fstring number format python 
Python :: how to get the year in python 
Python :: reverse shell python 
Python :: pandas scatter plot with different colors 
Python :: check pip installed packages inside virtualenv 
Python :: python hello wrold 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =