Home > Enterprise >  Need to get output of all weekdays starting from given date
Need to get output of all weekdays starting from given date

Time:11-04

Output is not how it should be

given_day = datetime.date(2022,10,31)
    dates = given_day   datetime.timedelta(days= 1)
    for i in range(0 - given_day.weekday(), 7 - given_day.weekday()):
        print(given_day.strftime("%A"))

Output should start from Monday and end to Sunday Output I get is: Monday Monday Monday Monday Monday Monday Monday Where i made a mistake :(

CodePudding user response:

I can't make head or tail of your code, but the following works:

given_day = datetime.date(2022,10,31)
for i in range(0   given_day.weekday(), 7):
    print(given_day.strftime("%A"))
    given_day  = datetime.timedelta(days=1)
  • Related