Prime Number | Check | Intervals | Python Language

Print the prime numbers in given two intervals :

 (coded in Python Language)



 

Introduction:

Prime numbers are numbers that have only 2 factors: 1 and themselves. For example, the first 10 prime numbers are 2, 3, 5, and 7, if we look at 11 it has two factors 1 and 11 that makes number 11 remainder zero(0).


Coding in Python (.py) :

""" THIS IS THE ALGORITHM FOR PRINTING RANGE OF PRIME NUMBERS"""

def range_prime(a,b):

""" Defining a function name range_prime that will print
the range between """

# checking a valid input

if (a < 0 or b < 0):
print('Enter greater than zero as input!!')
elif a == b :
print("Give a range between ",a,b)
elif (a > b ):
print( a," must be smaller than ",b)


else:

        # algorithm of prime numbers
      
for i in range(a,b+1):
for j in range(2,i+1):
if i%j==0:
break
if i == j:
print(i)

#call the function by passing value

range_prime(4,20)

  


Output :





---------------------------------------------------

Related Links :

Download: Python

Install : python

---------------------------------------------------

 


Comments

Popular posts from this blog

Print name in a pattern | name as abbreviation | C-Program