Weekends
Given two dates D1 and D2, write a program to count the number of Saturdays 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.
Output
The output should be a single line containing two integers separated by space
Explanation
For example, if the given dates are "25 Jan 2021" and "14 Feb 2021", the Saturdays and Sundays dates from "25 Jan 2021" to "14 Feb 2021" are
"30 Jan 2021" is a Saturday
"31 Jan 2021" is a Sunday
"6 Feb 2021" is a Saturday
"7 Feb 2021" is a Sunday
"13 Feb 2021" is a Saturday
"14 Feb 2021" is a Sunday
output
Saturday: 3
Sunday: 3
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
from datetime import date
def numOfDays(D1, D2):
num=(D2 - D1).days
if(num%7==0):
print('Number of saturday and sunday:',int(num/7))
else:
if(num%7<5):
print('Number of saturday and sunday:',int(num/7))
else:
if(num%7<6):
print('Number of saturday:',int(num/7)+1,'and number of sunday',int(num/7))
return num
# Driver program
D1 = date(2021, 3, 10)
D2 = date(2021, 3, 2)
print('Number of days between these two dates',numOfDays(D2, D1))
Comments
Leave a comment