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 :: how to uninstall python2.7 from ubuntu 18.04 
Python :: file.open("file.txt); 
Python :: keep only one duplicate in pandas 
Python :: pdf to csv 
Python :: run python notepad++ 
Python :: pd df append 
Python :: replace none with empty string python 
Python :: delete tuple from list 
Python :: pandas to dictionary 
Python :: linked lists python 
Python :: python if in range 
Python :: how to create enter pressed for qlineedit in pyqt5 
Python :: distance between numpy arrays 
Python :: python reference to back folder 
Python :: python diagonal sum 
Python :: random search cv 
Python :: python except print error type 
Python :: extract int from string python 
Python :: convert rgb to a single value 
Python :: random in python 
Python :: create requirement .txt 
Python :: python hide print output 
Python :: python get all combinations of list 
Python :: generate dates between two dates python 
Python :: how to remove duplicates from a python list 
Python :: access first element of dictionary python 
Python :: pythob password generator 
Python :: python open file for reading and writing 
Python :: matplotlib vertical line 
Python :: python - count total numeber of row in a dataframe 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =