Skip to content

Instantly share code, notes, and snippets.

@Makiyu-py
Created February 11, 2021 02:12
Show Gist options
  • Save Makiyu-py/bb9041072c9471a79221cfa584de75a6 to your computer and use it in GitHub Desktop.
Save Makiyu-py/bb9041072c9471a79221cfa584de75a6 to your computer and use it in GitHub Desktop.
A Progress Bar in 5 Lines of Python Code!
def create_progbar(total: int, current: int, *, bar_size: int = 20, comp="🟩", incomp="⬜"):
if current > total: return comp * bar_size, round((current / total) * 100, 2)
bar = ""
for i in range(bar_size): bar += comp if len(bar) < int(round(bar_size * (current / total))) else incomp
return bar, current / total
# Showing off outputs
for cur in [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]: # too lazy to add
pb, percentage = create_progbar(100, cur,
bar_size=22 # this is optional btw
)
print(f"{pb} - {percentage}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment