Article 6PA5X How to improve upon this code for finding prime numbers in a given range, using different ways.

How to improve upon this code for finding prime numbers in a given range, using different ways.

by
ajiten
from LinuxQuestions.org on (#6PA5X)
I have only in mind profilers, but that too need directions; and if other ways exist, then please tell.
The program finds all prime numbers in a given range.
Intend to make it like a professional code.
Code:import math
#print('Enter the number till which need find the prime numbers')
n = int(input('Enter the number till which need find the prime numbers : '))
list_prime=[]

for i in range (2,n+1):
prime = 0
val = math.ceil(math.sqrt(i))
print(f'sqrt of {i} is { math.sqrt(i)}, need check till : { val}')
for j in range (2, val+1):
print(f'i : {i}, j : {j}')
if (i % j == 0):
prime = 0
break
else:
prime = 1
if j < val:
continue
else:
list_prime.append(i)

print(f'list of prime numbers is : {list_prime}')
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments