Python Tutorial 5- Let’s Solve Few Questions using Python

Python Tutorial 5- Let’s Solve Few Questions using Python

 

Create function to find if a given year is leap year or  not. Provide year as parameter of the function.

 

def check_leap_year(year):
    is_leap_year=False
    if year%4==0:
        is_leap_year=True
try:
    check_leap_year(2018)
    print(is_leap_year)
except:
    print("Your code raised an error")
Create function if a list of years given then find which year is leap year or not. Provide starting and end year as two year as parameter of the function.

 

def leap(start,end):
    for i in range((end-start)+1):
        try:
            year=start+i
            t=i%4
            if t==0:
                print(str(year)+ " is leap year")
            else:
                print(str(year)+ " is not leap year")
            
        except:
            print( "nothing is valid")
            continue

 

LEAVE A COMMENT

Code Calibre