Skip to content

Instantly share code, notes, and snippets.

@runningzyp
Created March 23, 2023 04:44
Show Gist options
  • Save runningzyp/0056a5de52086bf792412f035c3641e2 to your computer and use it in GitHub Desktop.
Save runningzyp/0056a5de52086bf792412f035c3641e2 to your computer and use it in GitHub Desktop.
# |░▒▓███████░░░░░░░░░░| 50.0% completed
# def progress_bar(current_progress, total_progress):
# bar_length = 20
# filled_length = int(bar_length * current_progress // total_progress)
# bar_list = ['░', '▒', '▓', '█']
# bar = ''.join([bar_list[min(i,3)] for i in range(filled_length)]
# bar += ''.join([''░' for i in range(bar_length-filled_length)])
# percent = "{:.1f}".format(100 * (current_progress / total_progress))
# result = f'|{bar}| {percent}% completed'
# print(result)
# return result
# |███████▓▒░ | 50.0% completed
def progress_bar(current_progress, total_progress):
bar_length = 20
filled_length = int(bar_length * current_progress // total_progress)
bar_list = ["░", "▒", "▓", "█"]
bar = "".join([bar_list[min(i, 3)] for i in range(filled_length)])[::-1]
bar += "".join([" " for _ in range(bar_length - filled_length)])
percent = "{:.1f}".format(100 * (current_progress / total_progress))
result = f"|{bar}| {percent}% completed"
print(result)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment