python

Python Program to Display Prime Numbers in a Given Range

In this tutorial, we are going to see how to write a python program to display prime numbers in a given range using the “for” loop.

A positive integer greater than 1 that has no divisors other than 1 and the number itself is called a prime.

2, 3, 5, 7, etc. are prime numbers because they have no other divisors.
 

 

Python Program to Display Prime Numbers in a Given Range
#Read user input
min = int(input("Enter the min : "))
max = int(input("Enter the max : "))

for n in range(min,max + 1):
   if n > 1:
       for i in range(2,n):
           if (n % i) == 0:
               break
       else:
           print(n)

This example will print all prime numbers between 1 and 10.

Enter the min : 1
Enter the max : 10
2
3
5
7
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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