Python

Find Prime Numbers in Given Range in Python

Programmingempire

Today I will explain a simple application to Find Prime Numbers in Given Range in Python. In order to find the prime number in the given range, first, we need to set the range. For this purpose, we take two variables – upperlimit, and lowerlimit respectively. Also, take the input from the user in these two variables.

Further, we need to convert these numbers to integers. Because the input() function returns a string value. After that, we create another variable prime that indicates whether a number in the range is prime or not and set its value to 1.

Since we need to iterate from lower limit to upper limit, we use a for loop for this. After that, we need another for loop to check each number in the outer loop. Therefore, the if statement inside the inner for loop will check whether the number is divisible or not. If it is divisible, then the number is not prime.

Program to Find Prime Numbers in Given Range in Python

print('Prime Numbers in the Given Range!')
lowerlimit=input('Enter the Value of Lower Limit: ')
upperlimit=input('Enter the Value of Upper Limit: ')

llm=int(lowerlimit)
ulm=int(upperlimit)
prime=1
print('prime numbers in the range '+lowerlimit+' to '+upperlimit+' are...')
for p in range(llm, ulm+1):
	for i in range(2, int(p/2)+1):
		if(p%i==0):
			prime=0
			break
	if(prime==1):
		print(p)
	prime=1	 

Output

Output  of the Code to Find Prime Numbers in Given Range in Python
Output of the Code to Find Prime Numbers in Given Range in Python

Further Reading

Deep Learning Tutorial

Text Summarization Techniques

How to Implement Inheritance in Python

Find Prime Numbers in Given Range in Python

Running Instructions in an Interactive Interpreter in Python

Deep Learning Practice Exercise

Python Practice Exercise

Deep Learning Methods for Object Detection

Understanding YOLO Algorithm

What is Image Segmentation?

ImageNet and its Applications

Image Contrast Enhancement using Histogram Equalization

Transfer Learning and its Applications

Examples of OpenCV Library in Python

Examples of Tuples in Python

Python List Practice Exercise

Understanding Blockchain Concepts

Edge Detection Using OpenCV

Predicting with Time Series

Example of Multi-layer Perceptron Classifier in Python

Measuring Performance of Classification using Confusion Matrix

Artificial Neural Network (ANN) Model using Scikit-Learn

Popular Machine Learning Algorithms for Prediction

Long Short Term Memory – An Artificial Recurrent Neural Network Architecture

Python Project Ideas for Undergraduate Students

Creating Basic Charts using Plotly

Visualizing Regression Models with lmplot() and residplot() in Seaborn

Data Visualization with Pandas

A Brief Introduction of Pandas Library in Python

A Brief Tutorial on NumPy in Python

programmingempire

You may also like...