python进度条
import time
from math import sqrt
PW = 521025
def is_prime(n):
for i in range(3, int(sqrt(n))+2, 2):
if n % i == 0:
return False
return True
#进度条
class ProgressBar:
def __init__(self, total=0, width=50):
self.total = total
self.width = width
def show(self, count, done='#', wait='-'):
proc = self.width * count // self.total
ok, undo = done * proc, wait * (self.width-proc)
#print(f'\rRunning... [{ok}{undo}] {count}/{self.total}'.format(ok,undo,count,self.total), end='')
print("\rRunning... [{0}{1}] {2}/{3}".format(ok,undo,count,self.total), end='')
def main(total=PW):
n = 3
bar = ProgressBar(total)
for p in range(2, total):
while True:
n += 2
if is_prime(n):
bar.show(p+1)
break
if __name__ == '__main__':
main()