自定义进度条

1.自定义的进度条,拿去用

自定义进度条
# 自己写一个进度条
import time
def progress(count,counts,length=50,key="█",second=0.1):
    """
    :param count:  已完成的值
    :param counts: 总量
    :param length: 默认字符串长度
    :param key: 进度条字符
    :param second: 刷新间隔
    :return:
    """
    if count <= counts:
        count_str = int(count / counts * length) * key
        count_str = count_str.ljust(length, " ")
        percentage = round(count / counts * 100, 2)
        s = f"[{count_str}] {percentage}% | {round(count, 2)}/{round(counts, 2)}"
        print(f"\r{s}", end="")
        time.sleep(second)
        if percentage == 100:
            print()
    else:
        progress(counts,counts)


if __name__ == "__main__":
    count = 0
    counts = 30
    while True:
        count += 0.3
        progress(count,counts)
        if count>counts:
            break
View Code

 自定义进度条

 

上一篇:14.LeetCode 三个数和


下一篇:[LeetCode] 1157. Online Majority Element In Subarray 子数组中占绝大多数的元素