樱花味的棉花糖 2023-03-22 20:03 采纳率: 66.7%
浏览 19
已结题

python文本进度条

设计一款文本进度条,前50%的进度很快达到,后面在进度相对慢些

  • 写回答

2条回答 默认 最新

  • 海洋 之心 2022年度博客之星人工智能领域TOP 1 2023-03-22 20:28
    关注

    实现起来很容易的,在后期适当加入个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条)

报告相同问题?

问题事件

  • 系统已结题 3月31日
  • 已采纳回答 3月23日
  • 创建了问题 3月22日