Prime Number Using Python

""" Finding prime number using function, for list of element """
def prime(num):
    if num <= 1:
        return False    #since 1 is not a prime number
    if num <= 3:
        return True      #since 3 is a prime number

    if num % 2 == 0 or num % 3 == 0:
        return False      #since n is divided by more than one  number

    i = 5
    while i * i <= num:
        if num % i == 0 or num % (i + 2) == 0:
            return False
        i += 6

    return True

def prime_in_range(start, end):
    primes = []
    for num in range(max(2, start), end + 1):
        if prime(num):
            primes.append(num)
    return primes

start_range = int(input("Enter the start  range: "))  #Eg.: if 8 to 34 enter 8
end_range = int(input("Enter the end of the range: ")) #Eg.: if 8 to 34 enter 34

prime_nums = prime_in_range(start_range, end_range)
count=len(prime_nums)
print("There are ",count ,"Prime number in the given range.")
print("Prime nums in the range from", start_range, "to", end_range, "are:",prime_nums)
#----------------------------  finding prime number or not -----------------------------------

# A number is said to be prime if it is divisible by itself and 1 only
 
num = int(input("Enter the number"))
count =0
for i in range(1,num):
    if(num % i == 0):
        count +=1
        
if(count< 2):
        print(num ,"is a prime number.")
else:
    print(num,"is not a prime number.")

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available