Prime Utilities
You are tasked to work on a project where you need to frequently verify the primality of numbers and get a sequence of prime numbers. To simplify your work and make your code reusable, you decided to create a module named
prime_utils.py
which contains two functions: is_prime
and get_primes
.is_prime
is a function that takes a single number as an argument and returns True
if the number is prime and False
otherwise. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.get_primes
is another function that takes an integer n
as an argument and returns the first n
(1 ≤ n ≤ 100) prime numbers in ascending order. It should use the is_prime
function as part of its implementation.The input and output are handled automatically by the
main.py
module.Input | Output |
print(is_prime(5)); print(is_prime(9)) | True
False |
print(get_primes(5)); print(get_primes(10)) | [2, 3, 5, 7, 11]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29] |
Note: Keep in mind that the number
1
is not considered a prime number.Constraints
Time limit: 2.4 seconds
Memory limit: 512 MB
Output limit: 1 MB