Write code to tell me the first and third Thursday’s of every month.
- User
Write code to tell me the first and third Thursday’s of every month.
Assistant
Here is Python code to print the first and third Thursday of every month:
pythonimport calendar import datetime now = datetime.datetime.now() year = now.year for month in range(1, 13): cal = calendar.monthcalendar(year, month) first_week = cal[0] third_week = cal[2] first_thursday = first_week[calendar.THURSDAY] third_thursday = third_week[calendar.THURSDAY] print(datetime.date(year, month, first_thursday)) print(datetime.date(year, month, third_thursday))This uses the calendar module to get a matrix of weeks for each month. It then indexes into the first and third weeks to get the Thursday date. The datetime module is used to print out the final date in a readable format.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.