Unlucky days

Language: Python


To calculate the number of Friday 13ths in any given year. The function is to be passed the year in an integer form and must return an integer.


from datetime import datetime, timedelta

def unlucky_days(year):
    #create a date that is the first day of the given year in String format
    date = datetime.strptime("01-Jan-"+ str (year), '%d-%b-%Y')
    Fridays = 0
    #create a loop through the days of the year
    for x in range(0, 365):
        #check to see if the weekday is Friday and the day of the month is the 13th. If so add one to the count
        if date.weekday()==4 and date.day==13:
        #Add one on to the date
        date = date + timedelta(days = 1)

    return Fridays

From: www.codewars.com