Skip to content

Instantly share code, notes, and snippets.

@AlgorithmAlchemy
Created June 29, 2023 10:41

Revisions

  1. AlgorithmAlchemy created this gist Jun 29, 2023.
    15 changes: 15 additions & 0 deletions bar.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import time

    def progress_bar(progress, total, bar_length=40):
    filled_length = int(bar_length * progress // total)
    bar = '█' * filled_length + '-' * (bar_length - filled_length)
    percentage = progress / total * 100
    print(f'Progress: [{bar}] {percentage:.2f}%')

    def simulate_process(total_time):
    for t in range(total_time + 1):
    progress_bar(t, total_time)
    time.sleep(1)

    total_time = 20
    simulate_process(total_time)