Last active
August 4, 2022 15:32
-
-
Save tusharhero/77b4d317739dfa9db7beeceaae68bf14 to your computer and use it in GitHub Desktop.
prime numbers generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A python script to generate prime numbers | |
def getfactors(n): | |
factors = [] | |
for num in range(1,n+1): | |
if n%num == 0: | |
factors.append(num) | |
return factors | |
def isitprime(n): | |
return len(getfactors(n)) == 2 | |
def getprimes(r): | |
primes=[] | |
for n in range(1,r): | |
if isitprime(n) == True: | |
primes.append(n) | |
return primes | |
print(getprimes(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment