-1

An event occurs every X days in a year . The program must print the dates in which the event occurs in year Y as the output. The value of X and Y are passed as the input. The format of the date must be DD-MMM-YYYY.

Input:

X = 25
Y = 2021
Output:

25-Jan-2021
19-Feb-2021
16-Mar-2021
10-Apr-2021
05-May-2021
30-May-2021
24-Jun-2021
19-Jul-2021
13-Aug-2021
13-Aug-2021
07-Sep-2021
02-Oct-2021
27-Oct-2021
21-Nov-2021
16-Dec-2021
THUNDER 07
  • 521
  • 5
  • 21

1 Answers1

1
from datetime import datetime, timedelta

X = 25
Y = 2021

_start = datetime(Y,1,1)-timedelta(1)

while (_start + timedelta(X)).year <= Y:
    _start += timedelta(X)
    print(_start.strftime('%d-%b-%Y'))

  • Welcome to StackOverflow. While this code may answer the question, providing additional context regarding *how* and/or *why* it solves the problem would improve the answer's long-term value. – Sven Eberth Jun 24 '21 at 20:22
  • dude you rocked it how can I learn more about date time and calendar libraries. – THUNDER 07 Jun 25 '21 at 05:37
  • thanks. datetime (the one used here, built-in) is pretty powerful by itself, dateutils is another good one. To learn more, original documentation is always the best place to start. Here is the link to datetime doc: [link](https://docs.python.org/3/library/datetime.html) – jerryRigsNothing Jul 06 '21 at 14:03