Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Weekend Counter by keromage
from datetime import date, timedelta
def checkio(from_date, to_date):
delta = to_date - from_date
td = timedelta(days=1)
holidays = 0
for i in range(delta.days + 1):
dates = from_date + td * i
if dates.strftime("%a") == "Sun" or dates.strftime("%a") == "Sat":
holidays += 1
return holidays
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(date(2013, 9, 18), date(2013, 9, 23)) == 2, "1st example"
assert checkio(date(2013, 1, 1), date(2013, 2, 1)) == 8, "2nd example"
assert checkio(date(2013, 2, 2), date(2013, 2, 3)) == 2, "3rd example"
Dec. 22, 2019