You can download this code by clicking the button below.
This code is now available for download.
This function returns all prime numbers less than or equal to the given number n.
Technology Stack : Built-in functions, list comprehensions, for loops, all function
Code Type : Function
Code Difficulty : Intermediate
def get_prime_numbers(n):
if n < 2:
return []
prime_numbers = [2]
for i in range(3, n + 1, 2):
is_prime = all(i % p != 0 for p in prime_numbers if p * p <= i)
if is_prime:
prime_numbers.append(i)
return prime_numbers