Computer Science, asked by Rajeshraja9211, 9 months ago

Write A Simple Python Program With A Function To Find All Prime Numbers Within A Given Range.

Answers

Answered by sswaraj04
0

Answer:

start = 4

end = 20

check=0

for i in range(start,end+1)

if i>1:

for div in range(2,i):

if (i%div)==0:

check=0

break

else:

check=1

if check==1:

print(i)

Explanation:

here start is starting value of range and end is last value of the range

You can take it from user too

Modify it accordingly

Prime number is that which doesn't divide by any number except 1 and itself

Hope it helps :-)

Answered by anindyaadhikari13
1

Question:-

Write a Python Program with a function to find all prime numbers within a given range.

Program:-

def isPrime(n):

c=0

for i in range(1, n+1):

if n%i==0:

c=c+1

return c==2;

a=int(input("Enter the starting range: "))

b=int(input("Enter the ending range: "))

for i in range(a, b+1):

if isPrime(i):

print (i)

Indentation is very important for this program. Remember it.

Similar questions