def eratosthenes_timing ( nmax ): from time import perf_counter L = list ( range ( 2, nmax + 1 ) ) P = [] tic = perf_counter ( ) # Start the clock. while ( L != [] ): p = L[0] P.append ( p ) for l in L: if ( l % p == 0 ): L.remove ( l ) toc = perf_counter ( ) # Stop the clock. print ( 'eratosthenes ( ', nmax, ' ) required ', toc - tic, ' seconds' ) # # Here is how to reference the last element in a list: # print ( ' Number of primes found was ', len ( P ) ) print ( ' Biggest prime found was ', P[-1] )