import cmath prime_list = [k for k in range (500, 600)] primes = [] for i in prime_list: root = cmath.sqrt(i).real flag = True for j in range(2, int(root) + 1): if i % j == 0: flag = False print(i) break if flag: primes.append(i) print(primes)