Created
November 18, 2021 10:26
-
-
Save tabebqena/f8526677a7e9a009341eb424b1e47e3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import timedelta | |
| durations = [] # list of durations in seconds | |
| for x in range(0, 1000): | |
| durations.append(1000) | |
| # durations now contain 1000 elemnt , each of them = 1000 | |
| total_in_seconds = sum(durations) | |
| print(total_in_seconds) | |
| # it is = 1 milion | |
| # 1 milion seconds is more than 11 days. | |
| total = timedelta(seconds=total_in_seconds) | |
| print("Total durations: ", total) # 11 days, 13:46:40 | |
| print("Total days: ", total.days) # > int 11 | |
| print("total seconds EXcluding the 11 days", total.seconds) | |
| print("convert this ", total.seconds, " seconds to hours, minutes ") | |
| hours = total.seconds // 3600 | |
| print("hours: ", hours) | |
| # how many seconds remaining | |
| # after subtraction of the seconds consumed by the hours? | |
| remaining_seconds = total.seconds - (hours * 3600) | |
| print("remaining seconds: ", remaining_seconds) | |
| minutes = remaining_seconds // 60 | |
| print("minutes: ", minutes) | |
| seconds = remaining_seconds - (minutes * 60) | |
| print(seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment