import time def draw_progress_bar(percent, bar_length=20): filled_length = int(bar_length * percent) empty_length = bar_length - filled_length progress_bar = '█' * filled_length + '-' * empty_length print(f'Progress: [{progress_bar}] {percent:.0%}', end='\r') # 示例用法 total_iterations = 100 for i in range(total_iterations + 1): progress_percent = i / total_iterations draw_progress_bar(progress_percent) time.sleep(0.1) # 模拟长时间运行的进程