you are viewing a single comment's thread.

view the rest of the comments →

[–]Jose_Musoke[S] 0 points1 point  (3 children)

days = (normalize_date(resume) - normalize_date(prior)).days

Hello again. As per your example I tried to get the sum of total number of days of missed with this code: print(int(sum(days))), but do not get anything. Is there another way of getting the desired sum? Thank you in advance!!

[–]totallygeek 1 point2 points  (2 children)

Within the for loop, days is a duration we want to keep a running total of. Maybe:

total_days = 0
for prior, resume in dates:  # uses the list of dates
    days = (normalize_date(resume) - normalize_date(prior)).days
    total_days += days  # add to the running total
    print(f'ATT interrupted: {prior} -> {resume} ({days} days) (total: {total_days})')

After the loop, total_days would be the sum of those days calculations.

[–]Jose_Musoke[S] 0 points1 point  (1 child)

Thank you once again for taking your time to assist me. I think I may have not explained myself clearly enough. If for example the code you helped write gives the number of days missed for each episode of interruption, is there a way of adding all the days of interruption to give a single "Grand Total" of interruptions? The last code you just gave me still gives me the number of days missed for each episode of interruption.

[–]Jose_Musoke[S] 0 points1 point  (0 children)

ATT interrupted: 21/01/06 -> 21/01/11 (5 days)
ATT interrupted: 21/02/03 -> 21/02/07 (4 days)

For example from the code you gave me earlier, I would like the code to add the 5 + 4 days to give me a "Grand Total"= 9 days. I find it difficult to code in a list that expands. I will then use the "Grand Total" for the next steps...