def factors(n):
    return [x for x in range(1, n+1) if n % x == 0]

def prime(n):        
    return factors(n) == [1, n]

n = 30
primes = [x for x in range(1, n+1) if prime(x)]
print(primes)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: