Python Program to print Prime Numbers

Python Program to print Prime Numbers

To print the prime numbers in a range we need use the following code in Python program. Here we used 'print' method to print our desired output.

Prime Numbers in Python :



lower = int(input('Enter lower range : '))
upper = int(input('Enter upper range : '))
print("Prime numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)
           


Output :