MENU
Question -

Create a function that takes in a positive integer and return a list of prime numbers. A prime number is only divisible by 1 and itself.



Answer -

def primeNumbers(num):
primes = [ ]
i = 2
# iterates through range from 2 to
num(inclusive)
while i< =num:
# add ‘while’ condition
k = 2
is Prime = True
# check if prime number
while k
if i%k==0:
isPrime = False
k+ = l   # update k
if isPrime = =True:
primes.append(i)
i+ = l # update i
return primes

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×