I have written a Python program that prints out all the dates in yyy-mm-dd format within the year 2020. And now i try to write a program which loops/iterate through the year 2020 and prints out the sum of all the given numbers for each date. For ex: the sum of the date 2020-01-01 is 6 (2+0+2+0+0+1+0+1), the sum of the date 2020-01-02 is 7, etc. My problem is that i do not know how to write a code which takes out those numbers, adding them up and printing out for each date within 2020. I have also seen another post with the headline "Sum the digits of a number" but it did not really help me to solve my problem because the length of some months is not the same as the rest and also not the whole code was obvious.
def date_range(start, end): #creating a tuple function
for i in range(int((end - start).days)):
yield start + timedelta(i)
start = date(2020, 1, 1)
end = date(2020, 12, 31)
for each_date in date_range(start, end):
print(each_date.strftime("%Y-%m-%d") #iterating and printing all dates within the year of 2020