Python program to print all prime numbers in range

 

Python program to print all prime numbers in the given range

Write a Python program to accept a start number and end number from the user, and print all prime numbers in the given range (between the start and end number).

Video Tutorial

What is the meaning of a Prime Number..?

A number is said to be prime if it is not divisible by any other number except by 1 and itself.

For Example:

2, 3, 5, 7, and so on are prime numbers

4, 6, 8, 10, 12, 15, and so on are not prime numbers

Source Code to print all Prime Numbers in the given range Program in Python

start = int (input("Enter the starting range:"))
end = int (input("Enter the end range: "))

print ("Prime numbers in the range", start, "to", end)

for i in range(start, end+1):
    flag = 0
    for j in range(2, i):
        if (i % j == 0):
            flag = 1
            break
            
    if (flag == 0):
        print (i, end = ' ')

Output:

Case 1:

Enter the starting range: 10

Enter the end range: 100

Prime numbers in the range 10 to 100

11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Case 2:

Enter the starting range: 1

Enter the end range: 100

Prime numbers in the range 1 to 100

1 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

Summary:

This tutorial discusses how to write a python program to find all prime numbers in range. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *

Welcome to VTUPulse.com


Computer Graphics and Image Processing Mini Projects -> Click Here

Download Final Year Project -> Click Here

This will close in 12 seconds