-
Notifications
You must be signed in to change notification settings - Fork 0
/
s05_e0362.py
18 lines (14 loc) · 765 Bytes
/
s05_e0362.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- coding: utf-8 -*-
"""
Created on Thu May 12 13:51:18 2022
@author: Luke
Friday 13th or Black Friday is considered as unlucky day. Calculate how many unlucky days are in the given year. Find the number of Friday 13th in the given year. Input: Year as an integer. Output: Number of Black Fridays in the year as an integer. Examples: unluckyDays(2015) == 3 unluckyDays(1986) == 1 Note: In Ruby years will start from 1593.
"""
import datetime
def unlucky_days(year):
return sum(1 for month in range(1, 13) if datetime.date(year, month, 13).weekday() == 4)
print(unlucky_days(1986)) # expect 1
print(unlucky_days(2015)) # expect 3
print(unlucky_days(2012)) # expect 3
print(unlucky_days(2022)) # expect 1
print(unlucky_days(2029)) # expect 2