设计一款文本进度条,前50%的进度很快达到,后面在进度相对慢些
2条回答 默认 最新
关注实现起来很容易的,在后期适当加入个sleep函数就行了
import sys import time def progress_bar(percent): bar_length = 20 if percent > 100: percent = 100 if percent < 0: percent = 0 hashes = '#' * int(percent/100.0 * bar_length) spaces = ' ' * (bar_length - len(hashes)) sys.stdout.write("\rProgress: [{0}] {1}%".format(hashes + spaces, percent)) sys.stdout.flush() if percent <= 50: time.sleep(0.1) else: time.sleep(0.5)本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用