文本进度条的不同设计函数 python代码
时间: 2024-05-07 08:16:52 浏览: 121
我可以提供一些不同设计的函数代码示例:
1. 基础版文本进度条
```
import time
def progress_bar(total):
for i in range(total):
print('Progress: {}%'.format(int((i + 1) / total * 100)), end='\r')
time.sleep(0.1)
print()
```
2. 带有百分比显示与动画效果的文本进度条
```
import time
def progress_bar(total):
animation = '|/-\\'
for i in range(total):
print('Progress: {:.2f}% {}'.format((i + 1) / total * 100, animation[i % len(animation)]), end='\r')
time.sleep(0.1)
print()
```
3. 带有时间预计与动画效果的文本进度条
```
import time
def progress_bar(total):
animation = '|/-\\'
start_time = time.time()
for i in range(total):
elapsed_time = time.time() - start_time
time_remaining = (total - i - 1) / (i + 1) * elapsed_time
print('Progress: {:.2f}% {} Time remaining: {:.2f}s'.format((i + 1) / total * 100, animation[i % len(animation)], time_remaining), end='\r')
time.sleep(0.1)
print()
```
希望以上代码可以帮助您!
阅读全文