└── Fridays /Fridays: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | def count_fridays(year): 4 | # Initialize a counter for Fridays 5 | fridays_count = 0 6 | 7 | # Iterate through all months of the given year 8 | for month in range(1, 13): 9 | # Construct a date for the 13th day of the month 10 | date = datetime.date(year, month, 13) 11 | # Check if this date is a Friday (weekday() returns 4 for Friday) 12 | if date.weekday() == 4: 13 | fridays_count += 1 14 | 15 | return fridays_count 16 | 17 | # Example usage: 18 | year = 2024 # Replace with any year you want to calculate 19 | fridays = count_fridays(year) 20 | print(f"Number of Fridays in {year}: {fridays}") 21 | --------------------------------------------------------------------------------