Python Program to print all Prime Numbers in a Range


Using for loop

In [1]:
start = int(input("Please enter start number :"))
end = int(input("Please enter end number :"))


for number in range(start, end+1):
    for i in range(2, number):
        if (number % i == 0):
            break
    else:
        print(number)
Please enter start number :15
Please enter end number :25
17
19
23

In this program, we ask the user to input the range as the start and end number. After that, a for loop is used to loop through the range. Another for loop is used to find that if the number is divisible by any number below it or not. And if not, then it is printed on the console.