""" 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.")