Python Program to print Prime Numbers in given range

Write a python program to print all prime numbers between a given interval. A prime number is natural number greater than 1 which is only divisible by 1 and itself.

Python program to print all prime numbers in an interval

start = int(input("Enter lower limit of range: "))  
end = int(input("Enter upper limit of range: "))  
  
for number in range(start,end + 1):  
   if number > 1:  
       for i in range(2,number):  
           if (number % i) == 0:  
               break  
       else: 
           print(number, end = ", ")

Output:

Enter lower limit of range: 1
Enter upper limit of range: 100
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

Comments