python,文本进度条的实现过程

import time
scale = 100
print('执行开始'.center(103, '-'))
for i in range(scale + 1):
    a = '*' * i
    b = ' ' * (scale - i)
    c = (i / scale) * 100
    print('\r{2:4.0f}%[{0}{1}]'.format(a, b, c),end = '')
    time.sleep(0.1)
print('\n')
print('执行结束'.center(103, '-'))

程序运行效果:

--------------------------------------------------执行开始-------------------------------------------------
100%[****************************************************************************************************]

--------------------------------------------------执行结束-------------------------------------------------

posted @ 2020-03-03 16:01  Iceberg_710815  阅读(519)  评论(0编辑  收藏  举报