python进度条

import time

def show_progress_bar(progress):
    bar_length = 30
    filled_length = int(bar_length * progress)
    bar = '|' * filled_length + '-' * (bar_length - filled_length)
    percentage = int(progress * 100)
    print(f'\r[{bar}] {percentage}% ', end='', flush=True)

# 模拟进度更新
for i in range(101):
    progress = i / 100
    show_progress_bar(progress)
    time.sleep(0.1)

print('\n进度完成!')

发表评论

电子邮件地址不会被公开。 必填项已用*标注