Skip to content

Commit d0a2a7f

Browse files
committed
find prime in range
1 parent 0c41c33 commit d0a2a7f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Prime/code.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
def prime(range_from, range_to):
4+
5+
allList = [x for x in range(2, int(range_to)+1)]
6+
7+
ptr = 0
8+
while True:
9+
i = 2
10+
while i * allList[ptr] <= int(range_to):
11+
if i*allList[ptr] in allList:
12+
allList.remove(i*allList[ptr])
13+
i += 1
14+
ptr += 1
15+
if allList[ptr] ** 2 > int(range_to):
16+
break
17+
18+
19+
primeList = [x for x in allList if x > int(range_from)]
20+
print("Prime List Between ", range_from, " and ", range_to, " is")
21+
print(primeList)
22+
23+
24+
25+
if __name__ == "__main__":
26+
print("Enter the range of number")
27+
range_from = input("From: ")
28+
range_to = input("To: ")
29+
30+
prime(range_from, range_to)

0 commit comments

Comments
 (0)