I have this simple code (do pip install primesieve
first):
def prob(n):
it = primesieve.Iterator()
p = 1
prime = it.next_prime()
while prime <= n:
p = p * (1-1/prime)
prime = it.next_prime()
return p
How can I use tqdm to get a progress bar for the while loop?
import primesieve
def prob(n):
it = primesieve.Iterator()
p = 1
prime = it.next_prime()
pbar = tqdm(total=n)
while prime <= n:
p = p * (1-1/prime)
prime = it.next_prime()
pbar.update(prime)
return p
gives an incrementing clock but it doesn't give any indication of how complete the while loop is. That is there is no progress bar.
You can test this with prob(2**32)
.