Prime numbers Search
Explanations about prime numbers,:
- Definition of a prime number
- Method to check the primality of a number
- List of prime numbers,
are on this page: Primality test
This program lists the prime number within a given interval [a, b]. More precisely, it returns the number of prime numbers between a and b.
- As an intermediate step, we use the python prime number test.
- We go through the interval [a, b] with a for loop (index i). If i is prime, it is added to the list (mylist) with the append method.
- n% i means the remainder of the Euclidean division of n by i. If n% i = 0 then i divides n.
def is_prime (number): #1 is not prime if (number == 1): return False for i in range (2, number): if number% i == 0: return False return True def prime_numbers(a, b): mylist =  for i in range (a, b+1): if is_prime (i): mylist.append(i) return len(mylist), mylist