python 百分比的计算打印

 在做压测的时候常常需要统计测试成功率,简单的例子如下:

count = 89
i = 100
print("測試次數:%d"%count)
print("測試成功率:%.2f%%"%(count/i*100))

pyCharm 运行打印如下:

測試次數:89
測試成功率:89.00%

相对我目前的脚本,应用的情况如下:

if __name__ == "__main__"or True:
    from task import Task
    short = Task(cmds)
    count = 0
    for i in  range(1,1001):
        short.execute()
        if short.is_success:
            count +=1
        print("測試次數:%d"%count)
        print("測試成功率:%.2f%%"%(count/i*100))

原文地址:https://www.cnblogs.com/wellons/p/14205150.html