Python 进度条

# Author:Winter Liu is coming!
import time


def process_bar(num, total):
    rate_num = int(num*100/total)
    if rate_num == 100:
        r = "\r{}{}%\n".format("*"*rate_num, rate_num)  # \r回到行首,百分百就换行
    else:
        r = "\r{}{}%".format("*" * rate_num, rate_num)
    print(r, end="")


for i in range(1,21):
    time.sleep(0.2)
    process_bar(1000*i, 20000)

相关推荐