Answer to Question #256937 in Python for Raju

Question #256937

Weekends


Given two dates D1 and D2,write a program to count the number of Saturday's and Sundays from D1 to D2(including D1 and D2). The date in string format is like "8 Feb 2021".


Input


The first line of input will contain date D1 in the string format.

The second line of input will contain date D2 in the string format.


Sample input 1

25 Jan 2021

14 Feb 2021


Sample output 1

Saturday: 3

Sunday: 3


Sample input 2

25 May 2019

22 Dec 2021


Sample output 2

Saturday:135

Sunday: 135


1
Expert's answer
2021-10-28T05:26:06-0400
from datetime import datetime, timedelta




d1 = datetime.strptime(input(), '%d %b %Y')
d2 = datetime.strptime(input(), '%d %b %Y')
sat = 0
sun = 0
while d1 <= d2:
    if d1.weekday() == 6:
        sat += 1
    elif d1.weekday() == 0:
        sun += 1
    d1 += timedelta(days=1)
print(f"Saturday: {sat}\nSunday: {sun}")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS