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
Further Reading
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
Deep Learning Methods for Object Detection
Image Contrast Enhancement using Histogram Equalization
Transfer Learning and its Applications
Examples of OpenCV Library in Python
Understanding Blockchain Concepts
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