def factors(n):
return [x for x in range(1, n+1) if n % x == 0]
def prime(n):
return factors(n) == [1, n]
def nprimes(n, i=1, c=0, r=[]):
if c >= n: return r
if prime(i): return nprimes(n, i+1, c+1, [*r, i])
return nprimes(n, i+1, c, [*r])
for i in range(1, 11):
print(i, nprimes(i))
To embed this project on your website, copy the following code and paste it into your website's HTML: