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: ')
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):