Created
November 16, 2022 19:15
-
-
Save ruimelodev/19ec594aa0d4fcfdb31643d210dd7277 to your computer and use it in GitHub Desktop.
Get loop progress in Python
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
total = 12345 | |
step = 10 | |
iteration = 0 | |
for _ in range(total): | |
iteration += 1 | |
if (progress := iteration / total * 100) >= step: | |
print(f"Progress {round(progress)}% [{iteration}/{total}]") | |
step += 10 | |
# Output: | |
# Progress 10% [1235/12345] | |
# Progress 20% [2469/12345] | |
# Progress 30% [3704/12345] | |
# Progress 40% [4938/12345] | |
# Progress 50% [6173/12345] | |
# Progress 60% [7407/12345] | |
# Progress 70% [8642/12345] | |
# Progress 80% [9876/12345] | |
# Progress 90% [11111/12345] | |
# Progress 100% [12345/12345] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment