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

PREVIOUS NEXT
Code Example
Python :: raspberry pi keyboard python input 
Python :: bot ping command 
Python :: underscore in python 
Python :: matplotlib display graph on jupyter notebook 
Python :: Convert two lists into a dictionary in python 
Python :: how to find the closest value in column python 
Python :: python split string size 
Python :: blender scripting set active ojbect 
Python :: how do i get parent directory python 
Python :: how to search in django 
Python :: how to extract words from string in python 
Python :: python check if there is internet connection 
Python :: subtract current date from pandas date column 
Python :: delay print in python 
Python :: .launch.py file in ros2 
Python :: count_values in python 
Python :: python functions with input 
Python :: python projects with source code 
Python :: python password checker 
Python :: timer 1hr 
Python :: python raise typeerror 
Python :: make button bigger tkinter with grid 
Python :: python sum of list 
Python :: if number is divisible by 3 python 
Python :: how to create an entry box on tkinter python 
Python :: python md5sum 
Python :: add to python list 
Python :: cv2 blue color range 
Python :: convert plt image to numpy 
Python :: convert to datetime object 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =