A variation of determining leap years, assuming only integers are used and years can be negative and positive.

Write a function which will return the days in the year and the year entered in a string.  For example 2000, entered as an integer, will return as a string 2000 has 366 days

There are a few assumptions we will accept the year 0, even though there is no year 0 in the Gregorian Calendar.

Also the basic rule for validating a leap year are as follows

Most years that can be divided evenly by 4 are leap years. 

Exception: Century years are NOT leap years UNLESS they can be evenly divided by 400.

So the years 0, -64 and 2016 will return 366 days.
Whilst 1974, -10 and 666 will return 365 days.

Difficulty: introductory

Starter code:

def year_days(year):
	

Solutions:
def year_days(year):
    days = 365
    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        days += 1
    return "%d has %d days" % (year, days)

from calendar import isleap
def year_days(year):
  return "{} has {} days".format(year, isleap(year) + 365)

def year_days(year):
    return '{} has {} days'.format(year, 366 if year % 400 == 0 or (year % 4 == 0 and year % 100) else 365)

import calendar

def year_days(year):
    if calendar.isleap(year):
        return '{0} has 366 days'.format(year)
    else:
        return '{0} has 365 days'.format(year)

from calendar import isleap

def year_days(year):
    return f"{year} has {365 + isleap(year)} days"

year_days = lambda y: "{} has {} days".format(y, 365 + (y % 4 == 0) * ((y % 100 != 0) + (y % 400 == 0)) )

def year_days(year):
    x = 366 if (year % 100 != 0 and year % 4 == 0) or year % 400 == 0 else 365
    return '%d has %d days' % (year, x)
        


def year_days(year):
    leap = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
    return '{} has {} days'.format(year, 366 if leap else 365)

def year_days(year):
    leap = (year % 4 == 0 and year % 100 != 0) or (year % 100 == 0 and year % 400 == 0)
    return '{} has {} days'.format(year, 366 if leap else 365)

def year_days(year):
    if year % 100 == 0:
        if year % 400 == 0:
            return ("%s has 366 days" % year)
        else:
            return ("%s has 365 days" % year)
    else:
        return ("%s has 366 days" % year) if year % 4 == 0 else ("%s has 365 days" % year)

def year_days(year):
    days = 365
    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        days += 1
    return str(year) + " has " + str(days) + " days"

def year_days(year):
    leap = year % 4 == 0 and not year % 100 == 0 or year % 400 == 0
    number_of_days = 365 if not leap else 366
    return "{} has {} days".format(year, number_of_days)

def year_days(year): 
    days = 365 if year % 4 else 366 if year % 100 else 365 if year % 400 else 366
    return "{0} has {1} days".format(year, days)

from calendar import isleap

def year_days(year: int) -> str:
    """ Get the days in the given year. """
    return f"{year} has {366 if isleap(year) else 365} days"

def year_days(year: int) -> str:
    """ Get the days in the given year. """
    if not year % 4:
        if not year % 100:
            if not year % 400:
                days_per_year = 366
            else:
                days_per_year = 365
        else:
            days_per_year = 366
    else:
        days_per_year = 365

    return f"{year} has {days_per_year} days"

def year_days(year):
    return "%d has %d days" % (year, 365 + (not year % 400 if not year % 100 else not year % 4))

def year_days(y):
    return  f'{y} has {[365,366][y%4==0 and (y%400==0 or y%100!=0)]} days'

def year_days(year):
    return '{} has {} days'.format(year, 366 if year % 400 == 0 or (year % 100 != 0 and year % 4 == 0) else 365)

year_days = lambda y: "{} has {} days".format(y, __import__('calendar').isleap(y) + 365)


from calendar import isleap
def year_days(year):
  if isleap(year):
    return "{} has 366 days".format(year)
  return "{} has 365 days".format(year)

year_days=lambda y:'%d has %d days'%(y,365+(y%400<1or y%100and y%4<1))

year_days = lambda y: "%s has %s days" % (y, __import__("calendar").isleap(y) + 365)


def year_days(year):
    if (year % 4 == 0 and year % 100 == 0 and year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
        return f"{year} has 366 days"
    else:
        return f"{year} has 365 days"

def year_days(year):
    if year == 0:
        return '0 has 366 days'
    elif year % 100 == 0 and year % 400 == 0:
        return f'{year} has 366 days'
    elif year % 4 == 0 and year % 100 != 0:
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'

def year_days(year):
    if year % 100 == 0 and year % 400 != 0:
        return f'{year} has 365 days'
    elif year % 4 == 0:
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'


def year_days(year):
    if year % 100 == 0 and year % 4 == 0 and not(year % 400 == 0):
        return f'{year} has 365 days'
    elif year % 100 == 0 and year % 400 == 0:
        return f'{year} has 366 days'
    elif year % 4 == 0 and not(year % 100 == 0):
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'


def year_days(year):
    days = 365
    if year % 100 == 0:
        if year % 400 == 0:
            days += 1
    elif year % 4 == 0:
        days += 1
    return f'{year} has {days} days'

def year_days(year):
    if year==0:
        days=366
    elif year%100 ==0 and year%400 !=0:
        days =365
    elif year%4 != 0:
        days=365
    else:
        days=366
    return f"{year} has {days} days"

def year_days(year):
    is_leap_year = year % 4 == 0 and year % 100 != 0 or year % 400 == 0
    return f'{year} has {365 + int(is_leap_year)} days'

def find_leapyear(year):
    if year%4==0 and year%100!=0 or year%400==0:
        return 1
    else:
        return 0
def year_days(year):
    if find_leapyear(year):
        return f"{year} has 366 days"
    else:
        return f"{year} has 365 days"


def year_days(year):
    if abs(year) % 100 == 0:
        return f'{year} has 366 days' if abs(year) % 400 == 0 else f'{year} has 365 days'
    else:
        return f'{year} has 366 days' if abs(year)%4 == 0 else f'{year} has 365 days'

def year_days(year):
        
    if year % 100 == 0 and year % 400 ==0:
        return f'{year} has 366 days'
    elif year % 4 == 0 and year % 100 !=0:
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'
    
    


def year_days(year):
    leap = False
    if year % 100 == 0:
        if year % 400 == 0:
            leap = True
    elif year % 4 == 0:
        leap = True        
    
    return str(year) + ' has ' + str([365, 366][leap]) + ' days'

def year_days(year):
    return f'{year} has {"366" if year%4==0 and (year%100!=0 or year%400==0) else "365"} days'

def year_days(y):
    days = 365
    if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
        days = days + 1
    return "{} has {} days".format(y, days)

def year_days(y):
    #your code here
    if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0:
        return "{} has 366 days".format(y)
    return "{} has 365 days".format(y)

def year_days(year):
    x = 366 if year%4 == 0 else 365
    if year % 100 == 0 and year % 400 != 0:
        x = 365
    return f'{year} has {x} days'

def year_days(year):
    if (year % 4) == 0:
        if (year % 100) == 0:
            if (year % 400) == 0:
                d = '366'
            else:  
                d = '365'
        else:  
            d = '366'
    else:  
        d = '365' 
    
    return f'{year} has {d} days'

def year_days(year):
    if year%4 == 0:
        if year%100 == 0:
            if year%400 == 0:
                return str(year) + ' has ' + str(366) + ' days'
            
            else:
                return str(year) + ' has ' + str(365) + ' days'
        else:
            return str(year) + ' has ' + str(366) + ' days'
    else:
        return str(year) + ' has ' + str(365) + ' days'

def year_days(y):
    d = "365" if y%4 or (y%100 == 0 and y%400 != 0) else "366"
    return f"{y} has {d} days"

import datetime
def year_days(year):
    #your code here
    if year==0:
        return f'{year} has 366 days'
    elif year%400==0:
        return f'{year} has 366 days'
    elif year%100==0:
        return f'{year} has 365 days'
    elif year%4==0:
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'

def year_days(y):
    leap = 0
    if y % 400 == 0:
        leap = 1
    elif y % 4 == 0 and y % 100 != 0:
        leap = 1
    return '{} has {} days'.format(y,365+leap)

import calendar

def year_days(year):
    return '{} has 366 days'.format(year) if calendar.isleap(year) else '{} has 365 days'.format(year) 

def year_days(year):
    if year%400 == 0: return '{} has 366 days'.format(year)
    if year%100 == 0: return '{} has 365 days'.format(year)
    if year%4   == 0: return '{} has 366 days'.format(year)
    else            : return '{} has 365 days'.format(year)

def year_days(year):
    if not year%400:
        return f'{year} has 366 days'
    if not year%4 and year%100:
        return f'{year} has 366 days'
    return f'{year} has 365 days'

from calendar import isleap

def year_days(year):
    return f"{year} has {366 if isleap(year) else 365} days"

def year_days(year):
    leap = 0
    if year % 4 == 0:
        leap = 1
        if year % 100 == 0 and year % 400:
            leap = 0
    return f"{year} has {366 if leap else 365} days"


def year_days(year):
    return "{} has 365 days".format(year) if year % 4 != 0 else "{} has 365 days".format(year) if year % 100 == 0 and year % 400 != 0 else "{} has 366 days".format(year)

def year_days(w):
    return f'{w} has 36{5+(not w%4 and not (not w%100 and w % 400))} days'

def year_days(year):
    if year%4==0:
        if year%400==0 or year%100!=0:
            return str(year)+" has 366 days"
        else:
            return str(year)+" has 365 days"
    else:
            return str(year)+" has 365 days"

def year_days(year):
    if year ==0:
        return(f'{year} has 366 days')
    elif year%100 ==0 and year%400 == 0:
        return(f'{year} has 366 days')
    elif year%100 !=0 and year%4 == 0:
        return(f'{year} has 366 days')
    else:
        return(f'{year} has 365 days')

def year_days(year):
    #your code here
    if year%4 == 0:
        if year%100 == 0 and year%400 == 0:
            return (f'{year} has 366 days') 
        elif year%100 == 0 and year%400 != 0:
            return (f'{year} has 365 days')
        else:
            return (f'{year} has 366 days')
    else:
        return (f'{year} has 365 days')

def year_days(year):
    if (year%100!=0 and year%4==0) or year%400==0:
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'

def year_days(year):
    #your code here
    if year%100==0 and year%400==0:
        return f'{year} has 366 days'
    elif year%100!=0 and year%4==0: 
        return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'


def year_days(year):
    if year%4==0 and year%100==0 and year%400!=0:
        return str(year)+' has 365 days'
    else:
        return str(year)+' has 366 days' if year%4==0 else str(year)+' has 365 days'

def year_days(year):
    if year/4 == year//4:
        if year%100 == 0:
            if year%400==0:
                return f'{year} has 366 days'
            else:
                return f'{year} has 365 days'
        return f'{year} has 366 days'
    return f'{year} has 365 days'

def year_days(year):
    y = 365
    if year % 4 == 0 :
        y = 366
    if year % 100 == 0 :
        if year % 400 == 0 :
            y = 366
        else :
            y = 365
    return f"{year} has {y} days"

def year_days(year):
    #your code here
    if year%4==0:
        if year%100==0 and year%400==0:
            return '{} has 366 days'.format(year)
        elif year%100==0 and year%400!=0:
            return '{} has 365 days'.format(year)
        else:
            return '{} has 366 days'.format(year)
    else:
        return '{} has 365 days'.format(year)

def year_days(y):
    if y%100==0:
        return f'{y} has 366 days' if y%400==0 else f'{y} has 365 days'
    return f'{y} has 366 days' if y%4==0 else f'{y} has 365 days'

def year_days(year):
    leap = False
    if year % 4 == 0:
        leap = True
        if year % 100 == 0:
            leap = False
            if year % 400 == 0:
                leap = True
    
    if leap:
        days = 366
    else:
        days = 365
        
    return f'{year} has {days} days'

def is_leap_year(year):
    year = abs(year)
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return True
            else:
                return False 
        return True
            
    return False
        
        

def year_days(year):
    if is_leap_year(year):
        return f"{year} has 366 days"
    else:
        return f"{year} has 365 days"

def year_days(y):
    return f"{y} has {366 if (not y%400) or ((y%100) and not y%4) else 365} days"

def year_days(year):
    if year % 4 == 0:
        if year % 100 != 0:
            return '{} has 366 days'.format(year)
        elif (year % 100 == 0 ) and (year % 400 == 0):
            return '{} has 366 days'.format(year)
        else:
            return '{} has 365 days'.format(year)
    else:
         return '{} has 365 days'.format(year)

def year_days(year):
    res = ""
    res += str(year)
    if year%4 == 0:
        if year%100 == 0:
            if year%400 == 0:
                res += " has 366 days"
                return res
            else:
                res += " has 365 days"
                return res
        res += " has 366 days"
    else:
        res += " has 365 days"
    return res

def year_days(year):
    if year % 100 == 0:
        if year % 400 == 0:
            return "{} has {} days".format(year, 366)
        else:
            return "{} has {} days".format(year, 365)
    if year % 4 == 0:
        return "{} has {} days".format(year, 366)
    else:
        return "{} has {} days".format(year, 365)

def year_days(year):
    if year % 400 == 0:
        return str(year) + ' has 366 days'
    elif year % 100 == 0:
        return str(year) + ' has 365 days'
    if year % 4 == 0:
        return str(year) + ' has 366 days'
    else:
        return str(year) + ' has 365 days'

def year_days(y):
    return f'{y} has {365 + (1 if (not y % 4) and (y % 100 or not y % 400) else 0)} days'

def year_days(year):
    if (year / 100) % 1 == 0:
        if (year / 400) % 1 == 0:
            return str(year) + " has 366 days"
        else:
            return str(year) + " has 365 days"
    return str(year) + " has 366 days" if (year / 4) % 1 == 0 else str(year) + " has 365 days"

def year_days(year):
    day = '366' if year % 4 == 0 and year % 100 != 0 or year % 400 == 0 else '365'
    return f"{year} has {day} days"


def year_days(year):
    if year % 100 == 0 : return  f"{year} has 366 days" if year % 400 == 0  else f"{year} has 365 days"
    return f"{year} has 366 days" if year % 4 == 0  else f"{year} has 365 days"

def year_days(y):
    """
    leap year calculator
    """
    return "{} has {} days".format(y,[365,366,365,366][(y%4==0) + (y%100==0) + (y%400==0)])


def year_days(year):
    d=365
    if year % 100 == 0:
        if year % 400 == 0: #is leap
            d=366
    elif year % 4 == 0:
        d=366
    return str(year) + ' has ' + str(d) + ' days'

def year_days(year):
    if year % 400 == 0:
        return f'{year} has 366 days'
    elif year % 4 == 0 and year % 100 != 0:
        return f'{year} has 366 days'
    return f'{year} has 365 days'
    #your code here


def year_days(year):
    s=1
    if year % 100 ==0:
        if year % 400 ==0:
            s=1
        else:
            s=0
    return '{} has 366 days'.format(year) if year % 4 == 0 and s else '{} has 365 days'.format(year)

def year_days(y):
    day = '365'
    if y%100 == 0:
        if y%400 == 0:
            day = '366'
    elif y%4==0:
        day = '366'    
    return f'{y} has {day} days'

def year_days(year):
    d = '366' if ((year%4==0 and year%100!=0) or (year%400==0)) else '365'
    return f'{year} has {d} days'

def year_days(year):
    nb_days = 366 if year % 400 == 0 or (year % 4 == 0 and not year % 100 == 0) else 365
    return f'{year} has {nb_days} days'

def year_days(year):
    if year%4 == 0:
        if year % 100 == 0 and year % 400 != 0:
            return f'{year} has 365 days'
        else:
            return f'{year} has 366 days'
    else:
        return f'{year} has 365 days'

def year_days(year):
    if year % 4 != 0 :
        return f'{year} has {365} days'
    elif year % 4 == 0 and year % 100 == 0 and year % 400 != 0:
        return f'{year} has {365} days'
    else:
        return f'{year} has {366} days'
        
    



def year_days(year):
    msg = ' has 365 days'
    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        msg = ' has 366 days'
    return str(year) + msg

def year_days(year):
    
    abs_year = abs(year)
    leap_year = ' has 365 days'
    
    if abs_year % 100 == 0 and abs_year % 400 == 0:
        leap_year = ' has 366 days'
    elif abs_year % 100 != 0 and abs_year % 4 == 0:
        leap_year = ' has 366 days'
    
    return str(year) + leap_year

def year_days(year):
    return f'{year} has 366 days' if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) else f'{year} has 365 days'

def year_days(year):
    if year%4 == 0:
        if year%100==0:
            if year%400==0:
                return '{} has 366 days'.format(year)
        else:
            return '{} has 366 days'.format(year)
  
    return '{} has 365 days'.format(year)

def year_days(year):
    #your code here
    d = 0
    if int(year%400) == 0:
        d = 366
    elif  int(year%4) == 0 and int(year%100) != 0:
        d = 366
    else:
        d = 365
    return '{} has {} days'.format(year, d)
    


def year_days(year):
    mystr=str()
    if (((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)):
        days_in_year = 366
    else:
        days_in_year = 365
    mystr = str(year) + " has " + str(days_in_year) + " days"
    return mystr
    #your code here


def year_days(year):
    is_leap = ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)
    return f'{year} has {365 + is_leap} days'

def year_days(year):
    leap = 0 if year % 4 else 1
    cent = 0 if year % 100 else -1
    quad = 0 if year % 400 else 1
    return f"{year} has {365 + leap + cent + quad} days"

def year_days(year):
    days=365 if year%4!=0 or (year%100==0 and (year//100)%4!=0) else 366
    return "{} has {} days".format(year,days)

def year_days(year):
    return '{0} has {1} days'.format( year, 366 if is_leap( year ) else 365 )

def is_leap(year):
    if year %4 == 0:
        if year%100 == 0:
            if year%400 == 0:
                return True
            else:
                return False
        else:
            return True
    else:
        return False

def year_days(year):
    if year % 400 == 0:
        return "{} has 366 days".format(year)
    if year % 100 == 0 and year % 400 == 0:
        return "{} has 366 days".format(year)
    if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
        return "{} has 366 days".format(year)
    else:
        return "{} has 365 days".format(year)

def year_days(year):
    return f'{year} has 366 days' if year == 0 or (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)) else f'{year} has 365 days'

def year_days(year):
    if year%100 == 0 :
        return '{} has 366 days'.format(year)  if year%400 == 0 else '{} has 365 days'.format(year)
    elif year%4 == 0:
        return '{} has 366 days'.format(year)
    else:
        return '{} has 365 days'.format(year)



def year_days(year):
    if year%100==0:
        if year%400==0: return f'{year} has 366 days'
        else: return f'{year} has 365 days'
    else:
        return f'{year} has 366 days' if year %4 ==0 else f'{year} has 365 days'

def leap(year):
    solu = True
    if year >= 1000:
        if year%4==0:
            solu= True
            if year%100 == 0:
                if year%400==0:
                    solu = True
                else:
                    solu = False
        else:
            solu = False
    elif year >=100:
        if year%4==0:
            if year % 100 == 0:
                if year % 400 == 0:
                    solu = True
                else:
                    solu = False
        else:
            solu = False
    else:
        if year%4==0:
            solu = True
        else:
            solu = False

    return solu

def year_days(year):
    temp = year
    if temp == 0:
        return str(year) + " has 366 days"
    else:
        if temp < 0:
            temp *= -1

    if leap(temp):
        return str(year) + " has 366 days"
    else:
        return str(year) + " has 365 days"


from calendar import isleap
def year_days(year):
    #print(isleap(year)) # gives 1 if it is leap year
    return "{} has {} days".format(year, isleap(year) + 365)

def year_days(year):
    num_days = 365
    if year % 100 == 0:
        if (year / 100) % 4 == 0:
            num_days = 366
    elif year % 4 == 0:
        num_days = 366
    
    return '{} has {} days'.format(year, num_days)

def year_days(year):

    if str(year)[-2:] == '00' and year % 400 != 0:
        return f'{year} has 365 days'
    if str(year)[-2:] == '00' and year % 400 == 0:
        return f'{year} has 366 days'
    
    if year % 4 == 0:
        return f'{year} has 366 days'
    
    return f'{year} has 365 days'

def year_days(year):
    day =  year % 100 == 0 and year % 400 == 0 or not year % 100 == 0 and year % 4 == 0
    days = 5, 6    
    years = f'{year} has 36{days[day]} days'
    return years

def is_leap(year):
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return True
            else:
                return False
        else:
            return True
    else:
        return False

def year_days(year):
   if is_leap(abs(year)):
       return '{} has {} days'.format(year, 366)
   return '{} has {} days'.format(year, 365)   


def year_days(year):
    return "{} has {} days".format(year, 366 if (not year % 100 and not year % 400) or (not year % 4 and year % 100) else 365)
    #your code here