python基本學習 實現進度條

2022-08-10 19:45:18 字數 931 閱讀 6881

#python基本學習-實現fastpower進度條

#progress bar

import time

scale = 50

print("執行開始".center(scale//2, '-'))

start = time.perf_counter()

for i in range(scale + 1):

ratio = (i / scale)

fastpower = pow(ratio + (1 - ratio) / 2, 8)

movedbar = '*' * int(scale * fastpower)

residualbar = '.' * int(scale * (1 - fastpower))

percentfastpower = fastpower * 100

dur = time.perf_counter() - start

print("\r%[{}->{}]s".format(percentfastpower, movedbar, residualbar, dur), end = '')

time.sleep(0.1)

print("\n"+"執行結束".center(scale//2, '-'))

根據需要選擇不同的設計函式,本例選擇的函式為fastpower,開始執行慢,後面執行快

執行結果:

文字進度條的設計函式如下:

python實現進度條

sys.stdout.write 輸出不會自動換行,沒有end,可用轉義字元自行控制 n 換行 r 回車到本行首,可重新整理輸出 如用sys.stdout.write 和 r實現自定義進度條 import time import sysdef main j 0 for i in range 100 ...

Python 進度條簡單實現

考慮到進度條輸出的靈活性,最終是以文字形式返回而不是直接列印。這樣進度條和文字表達連線更加自由 python 3.6 author scc hy create date 2019 08 20 function 列表遍歷進度條 file name progressing class progress ...

學習進度條

周次 學習時間 新編寫 行數 部落格量 篇 學到知識點 第一周約21h 約100 11軟體工程概念 2學習軟體工程的規劃 第二週約25h 約100 11git的專案管理 2用目前學到的知識寫網頁版的複利計算器 3學習相關的web開發 第三週約5h 約200 11.在複利計算器中學習js 2.學習相關...