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".
sample input:
25 Jan 2021
14 Feb 2021
output:
Saturday: 3
Sunday: 3
from datetime import datetime, timedelta
if __name__ == '__main__':
print('Enter dates like: 31 May 2021')
a = datetime.strptime(input('First date : '), '%d %b %Y')
b = datetime.strptime(input('Last date : '), '%d %b %Y')
day = timedelta(days=1)
saturday = 0
sunday = 0
while a <= b:
if a.isoweekday() == 6:
saturday += 1
if a.isoweekday() == 7:
sunday += 1
a += day
print('satuday :', saturday)
print('sunday :', sunday)
Comments
Leave a comment