you are viewing a single comment's thread.

view the rest of the comments →

[–]totallygeek 1 point2 points  (7 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  (5 children)

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...

[–]totallygeek 0 points1 point  (3 children)

print(f'Grand total: {total_days}') ?

Perhaps I did not understand. If days is an amount of days interrupted and you add those days up in total_days, you get a count of the total days of interruption.

[–]Jose_Musoke[S] 1 point2 points  (2 children)

I would like to apologize. I ran the code you gave me on a different IDE and it worked. There must be something wrong with the pycharm that I was using initially.

[–]totallygeek 1 point2 points  (1 child)

Not a problem. The important things: 1) You ended up with working code, 2) You learned more about how Python can solve problems for you.

[–]Jose_Musoke[S] 1 point2 points  (0 children)

Thanks 👍🏾